Laravel 上传图片问题

  • Laravel 如何利用框架自带的方法实现 base 64 格式图片的上传
阅读 4.7k
2 个回答

答案是 Laravel 自身无法方法无法一步到位实现 base64 图片上传

不太理解,你说的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()}}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题