Tony Merryfield
Tony Merryfield

Reputation: 403

Using Laravel's File::makeDirectory to create a folder in the public directory

I have the following code in my controller - I am trying to create a directory structure to save files into:

use File;

...

$path = public_path().'/shared/uploads/images/brands/400';

if (!File::exists($path)) {
    File::makeDirectory($path, $mode = 0755, true, true);
}

When I run the controller I get the following error:

Intervention\Image\Exception\NotWritableException: Can't write image data to path (/home/tony/Git/website/public/shared/uploads/images/brands/800/17.png) in file /home/tony/Git/website/vendor/intervention/image/src/Intervention/Image/Image.php on line 150

Looking in my public directory I can see no directory structure has been created.

Looking at other examples of this code doing similar/same thing I can't see any difference with my code except that I am creating the directories in the public folder.

As always, any help appreciated.

Upvotes: 0

Views: 905

Answers (1)

Tony Merryfield
Tony Merryfield

Reputation: 403

This was a permission issue.

On my development machine I simply changed the owner of /shared to www-data:www-data:

sudo chown www-data:www-data ./shared/

Once I'd done that the controller worked fine, creating the rest of the directory structure.

Upvotes: 1

Related Questions