When the Apache Document Root is set to htdocs (in httpd.conf), e.g.
DocumentRoot "/Library/Apache2/htdocs"
what path should a cgi script use for an image located, say, here:
htdocs/my_imgs/pic.jpg
For example, suppose the cgi script is located in Apache's cgi-bin directory, and the cgi script has this line in it:
print '<img src="/my_imgs/blue_square.jpg" />';
That absolute path works fine for me: Apache is able to find the image and the image displays on the web page. It's my understanding that the leading slash refers to the Document Root.
However, this relative path also works:
print '<img src="../my_imgs/blue_square.jpg" />';
Why does that work? On the face of it, that path shouldn't work. The leading '..' says to go up one directory from the current directory. Presumably, the current directory is the cgi-bin directory, and going up one directory from that is the Apache2 directory. Then because there is no subdirectory in Apache2 called my_imgs, the path should fail.
Does Apache consider the cgi-bin directory to be a subdirectory of htdocs--even though in the filesystem the cgi-bin directory is outside of htdocs? Something else? Which is preferable, the absolute path or the relative path?
If someone were looking for tutorial ideas, I think it would be of great help to write a tutorial that lists the directory structure of Apache2, gives a brief description of each directory--emphasizing the importance of the logs/error_log--and then explains which paths will work in a cgi script and which paths are preferable. I've been searching the Apache web site and google for three days, and I can't find anything that addresses this question. Thanks.In reply to (OT) cgi: relative v. absolute paths, Apache by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |