laravel - 在共享主机上托管时如何解决 laravel 的图像上传问题?
问题描述
我正在使用托管程序来部署我的 laravel 项目我将所有文件上传到 public_html 文件夹中,然后进行了应用程序工作所需的所有必要更改。该应用程序似乎工作得很好,但是当用户尝试上传图像时存储在 storage/app/public/avatar 文件夹和 public/storage/avatar 文件夹中,因为我使用符号链接来链接这两个文件夹,但用户无法查看照片。这就是我回忆照片的方式
div class="profile-avatar" style="width: 400px;height:500px;border-radius: 0%;background-image: url('@if(Auth::user()->avatar == "avatar. png") {{ url("/imgs/".Auth::user()->avatar) }} @else {{ url("/storage/avatar/".Auth::user()->avatar) } } @万一');”
请帮我解决这个问题
解决方案
As you have no ssh access to run some command in shell, try this when uploading the image
1. Store image here: public_path() . 'img/filename.jpg'*
2. Save the 'img/filename.jpg' in database
3. Generate the image URL with url('img/filename.jpg')
// Output http://www.your-domain.com/img/filename.jpg
If you can manage shell access then try this:
Remove your current app/public/avatar directory, which is created inside of storage folder. Also remove your storage folder inside public !
After that via ssh cli, cd to your laravel project folder and create a symbolic link via following command
ln -sr storage public/storage
Hopefully it will solve your issue. I had same issue and mine got fixed via second method ( I had ssh access to my server ).
推荐阅读
- python - 检查字符串是否在字母列表中 - Python3
- html - 当我使用带透视的变换时,Safari 的错误
- google-cloud-dlp - 使用 Google DLP 有效地编辑字符串集合?
- firebase - FCM 免费版 使用限制
- python - 如何将控制从一个 tkinter 窗口传递到另一个窗口?
- intellij-idea - intellij hybris 类重新编译不起作用
- mongodb - 如何在mongoDB中将字符串拆分为多个字符
- javascript - 谷歌上的 node.js 操作保存对话数据
- c++ - 自定义窗口过程在一个单独的文件中
- sonarqube - SONAR SCANNER 未运行 - 无法连接到 sonarqube 服务器