0

My application denies access to upload files with certain extensions for some reason. It prints out the error:

fopen(C:\wamp64\www\storage\app\public/wrdjxF3EMbtGCUyXjSEWH5zeAu822ACeKikLPaCT.): failed to open stream: Permission denied

The file types that have given out this error so far are: .msg and .txt. I have no clue what causes this problem, other file types seem to work fine.

The controller function that handles the file uploads:

if($request->hasFile('document'))
{
    $files = $request->file('document');
    foreach($files as $file){
        if($file){
            $name = $file->getClientOriginalName();
            $size = $file->getClientSize();
            $size = number_format($size / 1048576,2);
            $path = $file->store('public');
            Document::create([
                'report_id' => $id,
                'report_type' => "App\VisitingReport",
                'file_path' => $path,
                'file_name' => $name,
                'file_size' => $size.' MB'
            ]);  
        }
    }
}

Any help would be appreciated, thanks.

I'm running this on a Windows computer using WAMP.

I am convinced that it has something to do with the permissions indeed. I'm already a step further, the file gets uploaded but this time without the extension.

Avion
  • 21
  • 6

2 Answers2

0

can you paste here what permissions you see for other file types and .txt after uploads. Run ls -la in the place where these files are stored and permission should be on far left. something like rwxr-wr-w. Paste here so that at least it can give a clue on what could be the issue.

Otherwise, once .txt file is uploaded you can run chmod 777 some.txt and see if you are still getting permission issue. If you aren't getting permission issue anymore than it's somehow creating .txt file with different permission. But it's not a good idea to do 777 for anything :D. But at least now you know what the problem is.

If permissions are the problem then here is a wonderful answer on this topic

How to set up file permissions for Laravel?

Good luck :) I'm not an expert just trying to help

0

I have faced with this error, but I don't know it works for you or not. put this in your .env file

FILESYSTEM_DRIVER = public

and link the public folder with storage folder with this command:

php artisan storage:link

I hope it works.

Mahdi
  • 206
  • 2
  • 14