首页 > 解决方案 > 在共享主机上托管时如何解决 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) } } @万一');”

请帮我解决这个问题

标签: laravelshared-hosting

解决方案


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 ).


推荐阅读