我正在尝试使用laravel应用程序实现blueimp jquery文件上传。https://github.com/blueimp/jQuery-File-Upload
我已经使用插件设置了可以正常工作的表格,但是在laravel中创建服务器端脚本来处理上传时遇到了问题。
我更改了表单操作,如下所示:
<form id="fileupload" action="{{ route('photos.post.upload') }}" method="POST"
enctype="multipart/form-data">
在main.js(插件的一部分)中,我已将网址设置为:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: '/photos/upload/'
});
在我的路线文件中,我创建了一条路线,如下所示:
Route::any('photos/upload', [
'as'=>'photos.post.upload',
'uses' => 'PhotosController@uploadImage'
]);
我在控制器中的功能:
public function uploadImage()
{
dd(Input::file());
return Response::json(
array(
"files" => array(
"name" => "post"
))
);
}
此时,我只想测试表单数据是否已接收。但是,上传时数据为空。
使用Route::any()
或Route::post()
都会出现301错误(永久移动)
检入google chrome后,看来POST正在按预期方式用于上传,并且看起来文件已包含在内。
所以。
Input::file()
返回空任何帮助表示赞赏
Laravel会重定向URL中是否存在尾部斜杠,就像您在at处一样url: '/photos/upload/'
,因此它将以301状态重定向到没有尾部斜杠的URL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句