鍍金池/ 問答/PHP/ Laravel 上傳圖片問題

Laravel 上傳圖片問題

  • Laravel 如何利用框架自帶的方法實現(xiàn) base 64 格式圖片的上傳
回答
編輯回答
你好胸

不太理解,你說的base64格式圖片是啥意思,我理解的base64是一種編碼方式,當然可以支持將jpg、png等格式的圖片編碼為base64格式。

后臺:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{

  public function store(Request $request)
  {

  // get current time and append the upload file extension to it,
  // then put that name to $photoName variable.
  $photoName = time().'.'.$request->user_photo->getClientOriginalExtension();

  /*
  talk the select file and move it public directory and make avatars
  folder if doesn't exsit then give it that unique name.
  */
  $request->user_photo->move(public_path('avatars'), $photoName);

  }
}




前臺:

{{Form::open(['route' => 'user.store', 'files' => true])}}
    {{Form::label('user_photo', 'User Photo',['class' => 'control-label'])}}
    {{Form::file('user_photo')}}
    {{Form::submit('Save', ['class' => 'btn btn-success'])}}
{{Form::close()}}

2017年3月17日 20:38
編輯回答
背叛者

答案是 Laravel 自身無法方法無法一步到位實現(xiàn) base64 圖片上傳

2017年8月18日 11:55