最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Image is not displaying in Laravel - Stack Overflow

programmeradmin1浏览0评论

I am trying to see image in this link http://127.0.0.1:8000/images/files/Safety/1738837934.png in my Laravel application. But I am getting 404 error while I try to see the image. I placed my images inside /public/storage/files/Safety/ folder.

I can see some images but some images are not visible.

I am trying to see image in this link http://127.0.0.1:8000/images/files/Safety/1738837934.png in my Laravel application. But I am getting 404 error while I try to see the image. I placed my images inside /public/storage/files/Safety/ folder.

I can see some images but some images are not visible.

Share Improve this question edited Feb 6 at 11:22 abu abu asked Feb 6 at 10:49 abu abuabu abu 7,02223 gold badges82 silver badges155 bronze badges 2
  • 1 How can someone even help without seeing the code? – Dhruv Pandya Commented Feb 6 at 11:40
  • 2 Did you have a look at the Public Disk logic in Laravel? You can store your images in the storage folder, then symlink to the public directory, then display the images from there via the asset('storage/...') helper. Also yes, share your actual code next time so we don't have to guess at your approach/errors. – Tim Lewis Commented Feb 6 at 15:17
Add a comment  | 

2 Answers 2

Reset to default 4

You've put the file in one place and are trying to access it in another place.

The public directory is web root for your Laravel application, so if you've put the file in /public/storage/files/Safety/1738837934.png, then it would be accessible at http://127.0.0.1:8000/storage/files/Safety/1738837934.png.

If your images are stored in public/storage/files/Safety/ and some are not loading, follow these steps:

1. Check if the File Exists
Run:

ls -l public/storage/files/Safety/

Ensure the image exists.

2. Use the Correct URL
Try:

http://127.0.0.1:8000/storage/files/Safety/1738837934.png

Update your Blade template:

<img src="{{ asset('storage/files/Safety/1738837934.png') }}" alt="Image">

3. Create Storage Symlink
Run this command:

php artisan storage:link

4. Fix File Permissions
Set correct permissions:

chmod -R 775 storage public/storage
sudo chown -R www-data:www-data storage public/storage

5. Clear Cache & Restart Server

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan serve
发布评论

评论列表(0)

  1. 暂无评论