无法在目录Laravel中写入
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?
在我的服务器中,我收到此错误消息 p>
Unable 写入“/ home / company / blog / public / img”目录
code> pre>
当我尝试在我的控制器中上传这样的图像时 p>
$ 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}”]);
code> pre>
我知道这是关于授予我尝试的权限 p>
chmod 755 / home / company / blog / public / img
code> pre> \ n
但它仍然不起作用。 p>
我该如何解决这个问题? p>
div>
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