Home >PHP Framework >Laravel >Solve the problem that after laravel uploads images, there are images in the directory, but they cannot be accessed (404)

Solve the problem that after laravel uploads images, there are images in the directory, but they cannot be accessed (404)

藏色散人
藏色散人forward
2021-02-15 09:24:464389browse

The following column of Laraveltutorial will introduce to you how to solve the problem that there are pictures in the directory but cannot be accessed (404) after laravel uploads pictures. I hope it will help. Friends in need help!

Solve the problem that after laravel uploads images, there are images in the directory, but they cannot be accessed (404)

After laravel uploads pictures, there are pictures in the directory, but they cannot be accessed (404)

1. Problem description

The Laravel background uploads the image successfully and returns the access link, but when accessing the image, a 404 error occurs. Have you checked whether there are images in the corresponding directory?

2. Solution

  • As long as the public directory of the Laravel project can be accessed, access to other directories is not allowed, and images are uploaded to the storage directory by default, resulting in images The link is fine, but the image cannot be accessed.
  • How to do it? It's very simple. Create a file soft link under public
  • Execute the command: php artisan storage:link
  • After the command is executed, There will be an extra public/storage in the project.
  • This storage is a soft link, which points to the storage/app/public directory.
  • public/storage (soft connection) → storage/app/public
  • Then you can use the address to directly access the photos in public!

The above is the detailed content of Solve the problem that after laravel uploads images, there are images in the directory, but they cannot be accessed (404). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete