Hi,
I am having trouble with paths such as
/includes/new.php
however this works
../includes/new.php
I am running PHP on IIS
Any Ideas?
Thanks
Sinky
| SitePoint Sponsor |
Hi,
I am having trouble with paths such as
/includes/new.php
however this works
../includes/new.php
I am running PHP on IIS
Any Ideas?
Thanks
Sinky
Starting a path off with a slash (/) means it's absolute, i.e. starting from root. Starting with ".." makes it relative, starting up one from the current directory. "includes/new.php" (without the slash in front) tells the script to start from the current directory and look in "includes".
Sorry I should have made my slef more clear.
includes is at the root so i theory this should work from anywhere in the site
/includes/new.php
However it does not.
If I am in say www.somesite.com/test/new.php
I can get to www.somesite.com/includes/new.php
By doing ../includes/new.php
But not
/includes/new.php
Is this a php.ini thing
Thanks
Sinky
The directory "includes" is at the root of your ftp directory structure. This does not mean that it's actually the document root...
If you run this in your ftp root directory you can take a look at where your ftp directory is actually located and then make a correct absolute path.PHP Code:echo $_SERVER['DOCUMENT_ROOT'];
(A common way to fix this problem is to just use a constant before includes: so something likeyou can define BASE_DIR with $_SERVER['DOCUMENT_ROOT'] or set it to another value if the value of the server var is incorrect because of lacking server config or whatever)PHP Code:include (BASE_DIR . '/includes/new.php');



I have more or less the same problem...
when I'm in:
and need to get to:HTML Code:http://admin.mydomain.be/index.php
I useHTML Code:http://www.mydomain.be/includes/init.phpsince the document root for the admin.mydomain.be is a subfolder named 'admin' in the document root for mydomain.be.PHP Code:../includes/init.php
This works fine!
Now when I need to get to an image located in:
I useHTML Code:http://www.mydomain.be/pics/open/image.jpgbut the only thing I get is the famous "red cross"....PHP Code:../pics/open/image.jpg
the picture IS actually there cause when I try to reach it straight with:
I do see the image...HTML Code:http://www.mydomain.be/pics/open/image.jpg
any ideas?
thx!
Koen
The Path of excess leeds to the tower of wisdom (W. Blake)
http://admin.mydomain.be/
../pics/open/image.jpg
Where should this end?
/www/admin/
../pics/open/image.jpg
Where does this end?
Difference between server and browser view on the directory structure seems to be unclear~





The problem you're having, pompopom, is that you are confusing web paths and filesystem paths. Anything you send out to the browser (such as image paths) use web paths; anything you do server-side (such as PHP includes) use filesystem paths.
If your image is at http://www.mydomain.be/pics/open/image.jpg, then an absolute path would be /pics/open/image.jpg (although if your page is on the admin.mydomain.be subdomain, then you must include the domain in the path as well).
If your current script is in /home/pompopom/admin/index.php, and your include at /home/pompopom/includes/inc.php, then a relative path would be ../includes/inc.php and an absolute path would be /home/pompopom/includes/inc.php. Note that the /home/pompopom part is never seen by the browser yet is necessary for server-side absolute paths.



aha I see
So you can't make a relative path to images if they aren't in the same domain even if the actual path on the server is only 'a folder' away
thx, i didn't knew this
greetz,
Koen
The Path of excess leeds to the tower of wisdom (W. Blake)
Bookmarks