MansNotHot
MansNotHot

Reputation: 293

Image not found altough right relative path is specified

My website on my server does not want to show the on server saved image. The path is relative and to my information correct, but I always get a 404 error. Found no solution after browsing endlessly.

All nessecary information is found in the second picture posted.

In the Browser

In PHPStorm

Upvotes: 1

Views: 1283

Answers (1)

SteeveDroz
SteeveDroz

Reputation: 6156

Apparently, you use a Framework. The file you have in the view folder isn't the one you send to the browser, it's just a source file that will be used by your Framework entry point: public/index.php. Your root folder is therefore public.

Two things must then be understood:

  1. Even though the line your type is in application/view/index/index.php, the browser will only see it as index.php, located at the base of your site (http://localhost/index.php or somethig like that). The relative path must therefore be written as relative to public.
  2. As your root folder, public, is seen as http://localhost by the browser, you can't use .., there is nothing above the root of your website, for the browser. You must do one of the followings:
    1. Place your image in public/_images instead of application/_images (normally, all the files that can be sent without passing by the PHP preprocessor can go in public)
    2. Place it wherever you want and create a controller that maps a custom URL to your image. Something like /images/(:any) maps to a controller looking into your specific image folder (please, don't, it's not because you can that you should).

My advice: create a public/img folder and place it your images, then you load it with <img src="/img/title_image_me.jpeg" alt="My picture">. (The initial / is very important there!, it's understood as the root folder of your website, Linux-style).

Upvotes: 2

Related Questions