- Laravel 如何利用框架自带的方法实现 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()}}
2 回答2.5k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
1 回答1.6k 阅读✓ 已解决
1 回答845 阅读✓ 已解决
2 回答521 阅读✓ 已解决
938 阅读
2 回答563 阅读
答案是 Laravel 自身无法方法无法一步到位实现 base64 图片上传