Reputation: 1494
In my server, I get this error message
Unable to write in the "/home/company/blog/public/img" directory
When I try to upload an image like this in my controller
$file = $request->file('img');
$name = time() . '-' . $file->getClientOriginalName();
$file->move(public_path() .'/img/', $name);
$company = company::where('username', $username)->first();
$company->images()->create(['path' => "/{$name}"]);
I know it's about granting permissions I tried
chmod 755 /home/company/blog/public/img
But it still doesn't work.
How can I resolve this?
Upvotes: 2
Views: 10605
Reputation: 11340
This is a common case when your server uses different user than you use in console. You can have www-data
for web server and user
for console.
755
means full rights for owner and read+execute for the user's group and others (read this). So, when you chmod 755
as user
, you grant full access for user
and no write permission to www-data
.
You have to change owner of the directory to your server's user. If your server's user is www-data
, use
sudo chown -R www-data:www-data /home/company/blog/public/img
Upvotes: 8