wiiwila's avatar

Laravel 5.2 uploading file Unable to write in directory

I'm uploading files in my system and it works locally where am using windows and xampp but when upload to server where am using an Linux my file is not being uploaded. I'm getting an error that : FileException in File.php line 113: Unable to write in the "uploadFiles/student/fileuploads" directory it cannot be written in the 'uploadFiles/student/fileuploads' directory which is within the public folder. This is my code: $destinationPath = 'uploadFiles/'.$input['infolder']; // upload path $extension = Input::file('file')->getClientOriginalExtension(); // getting file extension $fileName = $input['type'] .'_'.sprintf("%06d",$input['id']) .'_'. date("Y-m-d_H-i-s") . '.' . $extension; // renameing image $upload_success = Input::file('file')->move($destinationPath, $fileName); // uploading file to given path

Thank you for your help. :)

0 likes
2 replies
tayalanil's avatar

@wiiwila you need to provide the full upload path.

And I think it should start something like /home/...

Let me know, if you are unable to find the path to your upload dir.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

Use a helper; https://laravel.com/docs/master/helpers#method-public-path

$destinationPath = public_path() . '/uploadFiles/'.$input['infolder']; 

and don't ever do this .$input['infolder'];

You can't trust the user, and by just merging in an input value, you are allowing them to write into any folder on your server if they have permissions.

And don't forget that you need to check if the folder where you want to move the file to exists

And don't allow just any content to be written. Restrict it to safe content. As far as I can see there is nothing to stop me uploading a script file.

7 likes

Please or to participate in this conversation.