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



  • 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.

ubuntu@ip:~/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


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

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

Answered By – Vlad Salabun

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published