fredemagi's avatar

Combining Intervention Image with Storage::put, yielding an error on Windows 10.

I'm coding a file upload for images in which I want to manipulate the image before uploading. However, when I combine Intervention Image's stream() with Laravel's built in Storage::put(), I keep facing the same error with: "file_put_contents(PATH): failed to open stream: Permission denied".

My code is like:

 $path = 'public/SOMENAME';

        $file = Image::make($image)
                        ->orientate()
                        ->resize(800, null, function ($constraint) 
                            {
                                $constraint->aspectRatio();
                                $constraint->upsize();
                            }); 


        Storage::put($path, $file);        

I have tried to change permission on both storage/, storage/SOMETHING and xampp's tmp-folder to 777 for all users and groups, but nothing seems to work. If I only use Storage::put() directly on the file, I face no issues. What could be wrong?

I use Windows 10 64bit and run the server with npm run watch.

Thank you in advance.

0 likes
6 replies
fredemagi's avatar

I shall try the suggested Storage-method when I get home later.

I have already tried the save-method, but the problem is that it fails with “(...) cannot write to the path...) when I have multiple files, so I thought I could avoid this error by facilitating the Storage-method.

fredemagi's avatar

Unfortunately, it did not work with

Storage::put($path, (string) $file->encode());

Still yields error with permission.

newbie360's avatar

$path is where you save the file with extension, $file is the content

Storage::put($path, $file); 

but you set the $path = 'public/SOMENAME';

actually it is the public disk

i don't know what about the $file

but can you try this

$saveAs = 'image.jpg';
......
......

Storage::disk('public')->put($saveAs, $file);  
1 like
fredemagi's avatar

@newbie360, thanks. That did the job.

In addition to this, if I want to facilitate Storage::putFile() instead, because it creates the unique filename for me, what should I place as 2 parameter? I have tried with both

Storage::putFile('photos', $file);

and

Storage::putFile('photos', new File($file));

but I'm not sure how to solve it. Maybe give tmp-path from $file as parameter?

newbie360's avatar
Level 24

if you want put it to public disk, so you can access it by url

just simple do this

Storage::disk('public')->putFile('photos', new File($file));

Please or to participate in this conversation.