skip to Main Content

I am new to php and trying to use a php code in my local system. The code is working fine but its images and static files are not loading properly. when i tried to debug the issue i found that the correct image link in browser renders the login page of the program.

This is a strange scenario and i am not finding any solutions in any platform.

The urls i am trying are http://localhost:8000/image/banners/RG1.jpg to access the public/image/banners directory.

I also have created a symlink and tried the url http://localhost:8000/storage/images/user/RG1.jpg to access image stored in storage/app/public/images/user directory. This also generates the same result. The screenshot of the output is attached below.
output screenshot

I guess there is some poblem in middleware or routing.

4

Answers


  1. you tried this command

    for link folder

    php artisan storage:link
    

    then use

    <img src="{{ asset('storage/images/user/RG1.jpg') }}">
    
    Login or Signup to reply.
  2. make sure you’r working on the same port and also make sure you’ve done php artisan storage:link.
    second methode try accessing via the public folder

    http://localhost/[PROJECT_FOLDER_NAME]/public/[REST_OF_IMG_PATH]
    or in your case 
    http://localhost:8000/[PROJECT_FOLDER_NAME]/public/[REST_OF_IMG_PATH]
    

    also try to delete the link that is made in the public folder and redo
    php artisan storage:link.
    and php artisan optimize.

    Login or Signup to reply.
  3. use php artisan serve and check .env file.

    into .env file have

    APP_URL=localhost:8000 change to

    APP_URL=127.0.0.1:8000

    delete /storage in /public directory
    and try to php artisan storage:link

    Login or Signup to reply.
  4. please check the rewrite URL in htaccess files .

    <img src="{{ asset('images/logo.png') }}" alt="" />
    

    Here i saved images in the public folder , then images folder then image. Try the same way

    .htaccess files inside public folder

    Options -MultiViews -Indexes

    RewriteEngine On
    
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    ### never deliver .git folders, .gitIgnore
    RewriteRule ^(.*/)?.git+ - [R=404,L]
    
    # 2nd line of defense (if no mod_rewrite)
    RedirectMatch 404 ^(.*/)?.git+
    

    then php artisan optimize

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search