1
votes

So I'm using laravel on a windows 10 machine with Xampp.

I am attempting to upload files from a form to storage/app/images/ but every time I attempt to do so I'm coming up a Permission issue.

ErrorException in FilesystemAdapter.php line 119: fopen(C:\xampp\htdocs\test\public): failed to open stream: Permission denied

The function which I'm uploading the file is

$request->file('imgurl')->storeAs('images',request()->file('imgurl')->getClientOriginalName());
return back();

Things I have done

  1. Checked the file is being passed, a dd($request->getClientOriginalName()) returns the files original name
  2. Checked the permissions on the storage/images folder. They are set to 755 (drwxr-xr-x 1)
  3. php artisan cache:clear, chmod -R 777 app/storage, composer dump-autoload
2
So windows 10 has chmod command? What did I miss. (cygwin?) - Kyslik

2 Answers

1
votes

It is an old thread, but I ran into the same issue and figured it out. This happens when your file upload fails. When the file upload fails, the file's realPath variable will point to Laravel's public folder, instead of the uploaded file (because there is none).

So in your code you should check if the fileupload was successful:

<?php
if($request->hasFile('imgurl'))
{
    // You can store the uploaded file here
}

As said, the source of your problem is an upload issue. You could check a couple of things.

  1. Did the upload exceed the upload_max_filesize value
  2. Did the upload exceed the post_max_size value
  3. Do you have the right permissions on the directory defined at upload_tmp_dir
0
votes

Check if your file size is not exceeding the 'upload_max_filesize' limit informed in your php.ini file.