Reputation: 1
I have following file sample structure for my website:
"**www.website.com/index.php**"
My all other pages are in "www.website.com"
I have a header.php
for all pages located in "**www.website.com/header.php**"
.
Now I have created an another new directory as:
**www.website.com/folder/index.php**
This internal index.php is also calling header.php with **"../"**
But I can't get the images which are called from header file for it.
Image path is like this: **www.website.com/images**
Can anyone tell me the Solution without using absolute path?
Upvotes: 0
Views: 856
Reputation: 1
The problem is not only with images.
Any file which is called from external header.php is showing missing in internal directory.
I am again repeating my query.
I have two index.php files. One is at root directory: www.website.com/index.php
and another is inside a folder like: www.website.com/folder/index.php
My header is in root directory which calls other files which are in root directory itself. But Same header is used for index.php in "Folder". There it shows the missing files.
I hope I an not confusing you. But please do reply for the solution. Thanks
Upvotes: 0
Reputation: 257
The best way is:
If you are having common configuration file or if not then create it.
Define an Global variable for the image path:
define("IMAGE_PATH", "<image_path>");
Now you can you this "IMAGE_PATH" variable on files/application.
Benefit is when sometimes there is also minor changes, then need to check the whole application, but here you need to change this variable's value only.
Upvotes: 0
Reputation: 9527
I would recomend to use absolute path with predefined variable.
Something like this:
define('PATH', 'www.website.com')
and then use it
PATH."/images/"
That way, you can migrate your web elsewhere and you wont have to solve rpoblems with incorrect relative path (like eg. if you will use AJAX)
Upvotes: 0
Reputation: 205
Start the path with '/' (so without the '..') indicates that it should start looking from your root.
Upvotes: 1