file_put_contents(path): failed to open stream: Is a directory

Environment:

  • Laravel Version: 5.8.29
  • PHP Version $ php --version: PHP 7.2.24 (cli)

Problem Statement:

I’m unable to download file from s3 to local disk using put method in created directory.

ErrorException (E_WARNING) : file_put_contents(/path/storage/4804_1626): failed to open stream: Is a directory

However, I’ve found that directory has been created with below permission. I tried setting permission 777 as passing third parameter in makeDirectory() method but it didn’t work.

<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c091e091208093c150c">[email protected]</a>:~/path/storage$ ll
drwxr-xr-x  2 www-data www-data     4096 Sep 20 07:07  4804_1626/

Files & Configuration:

$folderPath = Storage::disk('local')->makeDirectory($folderName, 0777);

$contents = Storage::disk('s3')->get('path/' . $fileName);

Storage::disk('local')->put($folderName, $contents); // Following line is throwing error

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to specify full path to file, not only folder:

Storage::disk('local')->put($folderName . '/' . $fileName, $contents);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x