我的路线是:
Route::get('/file', array(
'as' => 'files',
'uses' => 'fileController@getFileUpload'
));
Route::post('/uploadfile', array(
'as' => 'uploadfile',
'uses' => 'fileController@postfileupload'
));
现在我已经在我的/文件路由上进行了上传设置并将发布请求发送到/ uploadfile
uploadfile的代码在这里:
$file = Input::file('file_upload');
$destinationPath = 'files/CDN/'.str_random(8);
echo $filename = $file->getClientOriginalName();
$extension =$file->getClientOriginalExtension();
$uploadSuccess = Input::file('file')->move($destinationPath, $filename);
但我总是得到500(内部服务器错误)
我检查了我的目录CHMOD是0777 我正在链接到正确的路线,就像我从/ uploadfile中删除上面的代码并放置
echo 200;
它会返回成功。
我也尝试过添加刀片表单标签,但uploadifive实际上并不依赖于表单元素。它发布了AJAX。
答案 0 :(得分:0)
当你通过刀片Laravel方法从普通文件发布表单中看到响应的var_dump时,我终于得到了解决方法你会发现Uploadfile对象是用文件名创建的(在表单字段中指定)但是在另一方面,当您通过Uploadifive发送相同的请求时,您会发现它发送的数组包含一个名为[FileData]的节点,该节点包含该文件的对象,因此基本上您需要将该对象指针分配给$ file变量,如下所示它会完美地运作:
$data = Input::all();
$file = $data['Filedata'];
$destinationPath = public_path().'files/'.str_random(8);
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$uploadSuccess = $file->move($destinationPath, $filename);
if( $uploadSuccess ) {
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
像魅力一样工作:)