我正在使用以下代码在Laravel 5中使用redactor上传图像,没有任何问题,我是否还需要为此创建表单请求类?
Route::post('redactorUpload', function(App\Http\Requests $request)
{
$file = $request->file('file');
$fileName = $file->getClientOriginalName();
$request->file('file')->move(public_path().'/uploads', $fileName);
return Response::json(array('filelink' => '/uploads/' . $fileName));
});
答案 0 :(得分:0)
您可以使用请求类,静态方式...即
来解决此问题Route::post('redactorUpload', function()
{
$file = Request::file('file');
$fileName = $file->getClientOriginalName();
$file->move(public_path().'/uploads', $fileName);
return Response::json(array('filelink' => '/uploads/' . $fileName));
});
我假设您已使用方法“发布”和操作“ redactorUpload ”创建表单,并将enctype创建为“ multipart / form-data “
示例表格
<form action="redactorUpload" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="file" name="file" id="file">
<input type="submit" value="Upload File" name="submit">
</form>