A
A
alexandrnevajno12018-02-26 11:47:10
PHP
alexandrnevajno1, 2018-02-26 11:47:10

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);

And I add the path from the root to it:
$directory = DOCROOT . 'files/catalog/items/';
Then the file name. And I output it in src for img. But the image is not showing. However, if the path from src is entered in the address bar of the browser, the image is opened. Why isn't it showing up for me? And how then correctly to set an absolute path?
PS Maybe it's because I'm doing this on a local server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neol, 2018-02-26
@neol

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 question

Ask a Question

731 491 924 answers to any question