laravel 上传图片时无法在laravel 5.1中创建目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42509921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to create directory in laravel 5.1 when upload image?
提问by ???? ????
Error : Unable to create the "http:/localhost/shopping/public/src/img/" directory
错误:无法创建“http://localhost/shopping/public/src/img/”目录
my code :
$imageName = $product->id . '.' .
$request->file('image')->getClientOriginalExtension();
$request->file('image')->move(
url().'/public/src/img/', $imageName
);
回答by Alexey Mezenin
Use the public_path()
helper, not url()
:
使用public_path()
助手,而不是url()
:
->move(public_path('src/img/'.$imageName));
回答by Akhilesh Kumar
In my case issue was little bit different. I am using laravel 5.5. If i will use below code on my local system, then its work properly
就我而言,问题有点不同。我正在使用 Laravel 5.5。如果我将在本地系统上使用以下代码,则它可以正常工作
$destinationPath = public_path('images\post');
$image->move($destinationPath, $inputimg);
But on production same above code throwing error. Unable to create the "/var/www/mycar/public/images\post" directory
但是在生产中同样上面的代码抛出错误。 无法创建“/var/www/mycar/public/images\post”目录
If someone have same issue then change 'images\post'to 'images/post'
如果有人遇到同样的问题,请将“图片\帖子”更改为“图片/帖子”