Laravel存储链接无法在生产中使用 [英] Laravel storage link won't work on production

查看:52
本文介绍了Laravel存储链接无法在生产中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用storage_path保存图像,并将我的存储文件夹符号化为public_html

I'm using storage_path to save my images and I symbolic my storage folder to public_html

php artisan storage:link

在本地,一切正常,当我上载图像时,它将上载到存储文件夹中,并且其链接将出现在public文件夹中,但是由于我移至实时主机和生产模式,因此我的图像将上载到存储文件夹中,但是public_html/storage中没有任何内容,而且我无法将其放置在前端.

On the local everything works fine, when I upload an image it will upload in storage folder and link of it will appear in public folder but since I moved to live host and production mode my images will upload in storage folder but nothing in my public_html/storage and I'm not able to get them in my front-end.

/config/filesystems.php

'public' => [
  'driver' => 'local',
  'root' => storage_path('app/public/'),
  'url' => env('APP_URL').'/storage',
  'visibility' => 'public',
],

.env

FILESYSTEM_DRIVER=public

controller sample

if ($request->hasFile('image')) {
  $image = $request->file('image');
  $filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
  $location = storage_path('app/public/images/' . $filename);
  Image::make($image)->resize(1200, 600)->save($location);
  if(!empty($page->image)){
    Storage::delete('images/' . $page->image);
  }
  $page->image = $filename;            
}

有什么主意吗?

推荐答案

已解决

感谢您的所有帮助,我尝试在服务器上运行php artisan storage:link,但发现出于安全原因我的服务器已禁用symlink.

SOLVED

Thanks for all your helps, I tried to run php artisan storage:link on my server and I found out that my server has disabled symlink for security reason.

所以我更改了所有图像上传功能,将图像上传到我的public文件夹而不是storage文件夹中,现在一切正常.

So I have changed all my image uploading functions to upload images in my public folder instead of storage folder and now everything is working just fine.

这篇关于Laravel存储链接无法在生产中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆