We help IT Professionals succeed at work.

Issue to page

Hi,
Jpg file does exist in "/var/www/pict" path, but html file below is not able to show Jpg file. Why?

<html>
    <body>
        <!--div align="center"-->
        <div class="container" style="background:url('../pict/ID-10028343.jpg') no-repeat center top; Height:780px; Width:1220px; background-size:100% 100%; margin:0 auto; ">
        ...

Open in new window

Comment
Watch Question

Dr. KlahnPrincipal Software Engineer

Commented:
If the server is rooted at "/var/www", then remove the ".." and it should work.

Side note:  Path-relative file locations can cause trouble in HTML, and particularly so (n) years down the road when things are rearranged.  Better to keep image files in the same locations as the HTML files which use them, or in dedicated subdirectories e.g., "/graphics/standard/image32.png"
HuaMin ChenProblem resolver

Author

Commented:
I removed ".." but no improvement. How to check if it is rooted at "/var/www"?
Distinguished Expert 2019

Commented:
without knowing where your HTML file in relation to the pict folder it is hard to answer.

Commonly, the baseline of content is in /var/www/html root of the default web site.

/var/www is outside the web servers data such that placing pict here, and then an index.html in /var/www/html will never reach it

i.e. while you think ../pict from html will be valid, within the web server the index.html is at / and ../ still means /.

i.e. cd /
cd ../
pwd
meaning in the web server your /var/www/html is the root / your html page says ../pict is being translated /pict which is  /var/www/html/pict within the file system. Based on your description, the pict folder under /var/www/html/ does not exist and thus the error 403/4 no such directory or file......
If you have access to the shell
1 - what is rtge address of your web page? in most situarions would be /var/www/ or (on recent systelms) /var/www/html/ )
2 - what are the access rights and owner of your jpg file? in most cases owners would be www-data:www-data and rwxr-xr-x (or 755)
HuaMin ChenProblem resolver

Author

Commented:
Currently, Html file is in path below

/var/www/html

Why ../pict is not able to locate

/var/www/pict

path?
Distinguished Expert 2019
Commented:
Because as far as the webserver, Apache is concerned /var/www/html is the root. It can not go outside that base.

As far as the Apache webserver is concerned / is /var/www/html within the filesystem.

The same way as my example pointed out on the file system, to go one level up from /, the apc he webserver sees ../pict reference from index.html the same as /pict/ which does not exist.

Your HTML image ../pict is a relative reference to the HTML file and the Apache webserver definition, unrelated to the filesystem paths....