Answer the question
In order to leave comments, you need to log in
Why doesn't html see the absolute path ( define('DOCROOT', realpath(dirname(__FILE__)). DIRECTORY_SEPARATOR); )?
Hello. I want to draw a picture output, and set the path absolutely. I have this php constant:
define('DOCROOT', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
$directory = DOCROOT . 'files/catalog/items/';
Answer the question
In order to leave comments, you need to log in
The absolute path in the local file system is not the same as the absolute path of the web server.
Let's say your site is in /var/www and the image is in images/1.jpg
The absolute path will be /var/www/images/1.jpg
But for the web server, the root is set to /var/www and if you pass src="/ var/www/images/1.jpg", then the site address is added to this path (for example, http://127.0.0.1) and the request goes to the web server, which will look for /var/www/var/www/images/ 1.jpg, which is missing.
If you enter /var/www/images/1.jpg into the address bar of the browser, then the address automatically changes to file:///var/www/images/1.jpg and the image is displayed (provided that you have such a file there is).
In short, you don't need to use DOCROOT when outputting to HTML.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question