Laravel 如何利用框架自带的方法实现 base 64 格式图片的上传
2 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
不太理解,你说的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 回答
- 0 关注
- 377 浏览
添加回答
举报
0/150
提交
取消