我想保存我的图片存储空间。但是有一些错误。
以下是我在控制器中的代码;
if ($request->hasFile('site_logo')) {
$image = $request->file('site_logo');
$realname = pathinfo($request->file('site_logo')->getClientOriginalName(), PATHINFO_FILENAME);
$extension = $image->getClientOriginalExtension();
$new_name = $realname."-".time().$extension;
$image->storeAs('public/uploads', $new_name);
$path = Storage::url($new_name);
$settings->site_logo = $new_name;
$settings->site_logo_path = $path;
$settings->site_logo_alt_name = $realname;
}
数据库记录;
site_logo | /tmp/phpqTLyXY
site_logo_path | /storage/1518975452-logo.png
site_logo_alt_name | logo
问题;
1-为什么site_logo无法取代$new_name
“/ tmp / phpqTLyXY”?
2- $path
说“/storage/1518975452-logo.png”是图片网址。但当我说“project.app/storage/1518975452-logo.png”时,它说“对不起,找不到您正在寻找的页面。”它无法找到图像?
对不起英语知识不好:/
答案 0 :(得分:2)
您需要create a symlink:
php artisan storage:link
然后您将能够使用以下方式访问该图像:
project.app/storage/uploads/image_name.png