【发布时间】:2022-02-08 07:03:39
【问题描述】:
我在使用 Laravel forge 部署 Laravel 应用程序时遇到问题。我尝试在 Laravel 中使用 faker 包生成假图像,但是,
Cannot write to directory "/home/forge/my.domain/public/storage/images/products/cover_img"
at vendor/fakerphp/faker/src/Faker/Provider/Image.php:98
94▕ ) {
95▕ $dir = null === $dir ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
96▕ // Validate directory path
97▕ if (!is_dir($dir) || !is_writable($dir)) {
➜ 98▕ throw new \InvalidArgumentException(sprintf('Cannot write to directory "%s"', $dir));
99▕ }
100▕
101▕ // Generate a random filename. Use the server address so that a file
102▕ // generated at the same time on a different server won't have a collision.
在工厂文件中,
'cover_img' => $this->faker->image(public_path('storage/images/products/cover_img'), 640, 480, null, false),
这是我第一次使用云托管。使用共享主机时,我可以授予创建文件夹的权限,也可以手动创建文件夹。请帮我解决这个问题。谢谢!
***更新***
我更改了一些代码并再次尝试。
if(!File::exists(public_path().'/storage/images/products/cover_img'))
{ File::makeDirectory(public_path().'/storage/images/products/cover_img', 0777,true);
}
现在使用 Laravel forge 部署时出现错误,
ErrorException
mkdir(): Permission denied
如果有人能帮我解决这个问题,我真的很感激。
【问题讨论】:
标签: laravel forge cloud-hosting