selim's avatar

Public path not writable

Ok, so I am trying to upload a file and I think my script is ok. I am getting an "can't write image data to path" exception.

dd(is_writable($path . $filename)); returns false, I just can't figure out why.

I am using Laravel 4.2 with Homestead and vagrant. I tried to sudo chmod -R 777 the path I am trying to upload the file to, and I also tried the same on mypc/Homestead.

I would really be thankful if somebody helped me out.

0 likes
6 replies
ross.edman's avatar

What is the path you are trying to store too? Can you give an example of what $path and $filename variables would be?

bashy's avatar

Try using some of these Laravel facades, will give you an easy way to check if the dir is writable or if it's a dir.

// Determine if the given path is a directory
File::isDirectory('directory');

// Determine if the given path is writable
File::isWritable('path');

There's also these sweet helpers

// Get the path to the Laravel root folder
app_path();

// Get the path to the public folder
public_path();

// App root path
base_path();

// Get the path to the storage folder
storage_path();
1 like
Alias's avatar

Also check that the entire project is owned by yourself, not root. Although I think you'd come into more issues if this were the case.

1 like
ia728188's avatar

Did you find a solution for this? I am currently facing the same problem.

ItsRD's avatar

the problem over here was the ownership of the containing folder on the server. It was set to the 'root' user and was supposed to be owned by 'apache' to be written by our application.

Please or to participate in this conversation.