Difference between src and require or include (path)
From any file on the website, if I want to call the image posted to / ico, I:
$arrow = "/ico/arrow.png";
without any ../ ico / ect. or. / ico / etc.
Now if I want to include the header.php file saved in / test:
<?php
include "/test/header.php";
or
require "/test/header.php";
or
require_once "/test/header.php";
?>
It won't work. I have to specify the path with ../ or. /.
I don't understand the difference!
Thank!
+3
source to share
1 answer
Image sources and hrefs links are evaluated by the client (browser). This means that they refer to:
- Network root (if the URL starts with
/
). For the purposes of this answer, it is easier to describe it as: your domain. If you are at http://www.yourpage.com/folder1/folder2/file.php and link to/img/arrow.png
then it is assumed that you mean http://yourpage.com/img/arrow.png - The current directory (if the URL doesn't start with
/
or starts with./
). If you are on http://www.yourpage.com/folder1/folder2/file.php and link toimg/arrow.png
then it is assumed that you mean http://yourpage.com/folder1/folder2/img/arrow.png
Includes, on the other hand, evaluation by the server. This means that they refer to:
- Filesystem root (if path starts with
/
) - The current working directory of the script (if the path does not start with
/
or starts with./
)
+3
source to share