Laravel 5.6 如何在存储中正确保存图像
Laravel 5.6 How to do save images correctly on storage
我想保存我的图像存储空间。但是有一些错误。
这是我在控制器中的代码;
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”是图像 url。但是当我说 "project.app/storage/1518975452-logo.png" 时它说 "Sorry, the page you are looking for could not be found." 找不到图像 ?
抱歉英文知识不好:/
你需要create a symlink:
php artisan storage:link
然后您将能够通过以下方式访问图像:
project.app/storage/uploads/image_name.png
我想保存我的图像存储空间。但是有一些错误。
这是我在控制器中的代码;
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”是图像 url。但是当我说 "project.app/storage/1518975452-logo.png" 时它说 "Sorry, the page you are looking for could not be found." 找不到图像 ?
抱歉英文知识不好:/
你需要create a symlink:
php artisan storage:link
然后您将能够通过以下方式访问图像:
project.app/storage/uploads/image_name.png