tim3011's avatar

Upload image to a custom folder

I have my uploads folder in the same level as the storage folder and would like to upload file to the uploads folder but I am getting error message

failed to open stream: Permission denied

I am using the php function

move_uploaded_file($_FILES['picture']['tmp_name'], "uploads/" . $_FILES['picture']['name']);

and would like to continue using that not the laravel one

Storage::disk('local')->put($file->getFilename().'.'.$extension,  File::get($file));

as this does not work for me the question is how to get the move file function to take the storage path or get the permission to my desired storage folder

0 likes
5 replies
fabricecw's avatar

Hey

I would use the Storage::disk('local') method (or why is it important for you to use the php function?).

Note that the root directory of Storage::disk('local') is storage/app.

So I recommend to create there a subdirectory "uploads" and store your files into it: Storage::disk('local')->put('uploads/' . $file->getFilename().'.'.$extension, File::get($file));

So your file is located at:

storage/app/uploads/file.txt

tim3011's avatar

thanks for the reply but the storage disk path does not work within the mobile devices environment .I can only upload on the desktop, if I use my mobile the file is not uploaded I get error

file does not exists on the path

thats why will prefer to use straight php if you know how or why that is please help

fabricecw's avatar
Level 7

Hi Tim

Ok, I didn't try it out with a mobile device. Could you try this:

Storage::disk('local')->move($_FILES['picture']['tmp_name'], 'uploads/' . $file->getFilename() . '.' . $extension);

(I haven't tested this solution...)

Please or to participate in this conversation.