不显示用户头像

时间:2019-01-30 11:36:01

标签: laravel laravel-5

HTML标记

<img src="storage/app/avatars/23_avatar1548246815.bmp" alt="">

此路径上已经存在文件。但没有显示。 而且我也使用了php artisan storage:link,但没有用。 错误是“禁止服务器错误403”。

2 个答案:

答案 0 :(得分:2)

根据laravel文档。

The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the  public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to  storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.

To create the symbolic link, you may use the storage:link Artisan command:

php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:

echo asset('storage/file.txt');
  1. 我肯定会使用这种方法
<img src="{{asset('assets/images/image.png')}}">

链接到您的资产文件。

  1. storage/app/avatars应该是storage/app/pubic/avatars吗?

答案 1 :(得分:0)

如果您说该路径上存在文件,则表明问题出在文件权限上。将/ project / storage权限更改为777,删除public / storage文件夹,然后运行php artisan storage:link,然后再尝试一次。如果不是,请尝试为public文件夹授予777权限