0

I have my route:

Route::get('/file', array(
    'as' => 'files',
    'uses' => 'fileController@getFileUpload'
));

Route::post('/uploadfile', array(
    'as' => 'uploadfile',
    'uses' => 'fileController@postfileupload'
));

Now i have uploadifive setup on my /file route and sending post request to /uploadfile

code for uploadfile is here:

    $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);

but always i am getting 500 (Internal Server Error)

I checked my directory CHMOD is 0777 and i am linking to right route as when i remove above code from /uploadfile and place

echo 200;

it returns success.

I have tried adding blade form tag also but uploadifive actually does not depends upon form element at all. It post with AJAX.

4

1 回答 1

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);
}

像魅力一样工作:)

于 2014-12-31T14:02:54.933 回答