Lonare's avatar

Laravel 4 and uploadifive not working 500 (Internal Server Error)

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'); // your file upload input field in the form should be named 'file'

        $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.

Any help will be appreciated.

0 likes
5 replies
RachidLaasri's avatar

does the file upload or no?

If no, maybe you should check your form and add

'files' => true

to your form opening.

bashy's avatar

Note - there should be an error message from Laravel with that 500 error

Lonare's avatar

Hi Bashy,

I cant add any form items into uploadifive as it use ajax request

Lonare's avatar

I finally got the work around when you see the var_dump of the response from a normal file posting form via blade Laravel approach you will find the Uploadfile object is created with the name of file (specified in the form field) but on the other hand when you send the same request via Uploadifive you will find that it sends an array which include a node called [FileData] which holds an object for that file so basically you need to assign that object pointer to the $file variable like this and it will work perfectly:

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

Works like charm :)

bashy's avatar

Note - you can see responses of AJAX calls in the network tab of your browser.

Please or to participate in this conversation.