|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-09 18:17 UTC] dennis dot birkholz at nexxes dot net
Description:
------------
include statement seems to resolve the current working directory other than the rest of php so if I am in a symlinked directory an try to include a file using a relative path (containing ../), the include fails because the original path of the script is used to resolve the relative include and not the path the script is invoked from.
Reproduce code:
---------------
Asume the following files/directory structure:
Directory /test1
Directory /htdocs
Directory /htdocs/docs
Symlink /htdocs/test2 -> /test1
File /test1/index.php
File /htdocs/docs/docs.inc.php
DocumentRoot is /htdocs
File-Contents of /test1/index.php
<?php
include("../docs/docs.inc.php");
// ... other code
?>
Expected result:
----------------
No error, output generated by code after the include
Actual result:
--------------
An error: failed to open stream: No such file or directory
(/test1/index.php:2)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 15:00:02 2025 UTC |
I don't realy understand your problem ?! [root@pix sdv]# ls -alR .: total 16 drwxr-xr-x 4 root root 4096 Dec 17 17:44 . drwxrwxrwx 3 via ftponly 4096 Dec 17 17:44 .. drwxr-xr-x 2 root root 4096 Dec 17 17:45 docs drwxr-xr-x 2 root root 4096 Dec 17 17:46 test1 lrwxrwxrwx 1 root root 5 Dec 17 17:44 test2 -> test1 ./docs: total 12 drwxr-xr-x 2 root root 4096 Dec 17 17:45 . drwxr-xr-x 4 root root 4096 Dec 17 17:44 .. -rw-r--r-- 1 root root 24 Dec 17 17:45 docs.inc.php ./test1: total 12 drwxr-xr-x 2 root root 4096 Dec 17 17:46 . drwxr-xr-x 4 root root 4096 Dec 17 17:44 .. -rw-r--r-- 1 root root 50 Dec 17 17:46 index.php [root@pix sdv]# cat test1/index.php <?php include("../docs/docs.inc.php"); echo "ok\n"; ?> [root@pix sdv]# cat docs/docs.inc.php <?php echo "docs\n"; ?> No problem when i try this with apache : http://www.xxxx.com/sdv/test1/index.php http://www.xxxx.com/sdv/test2/index.php ==> same output : docs ok if you try this in command line. 3 cases : - pwd= test1 : php index.php => output docs ok - pwd= test2 : php index.php => output docs ok - pwd= anywhere else : php ./test1/index.php : include(): Unable to access ../docs/docs.inc.php which is quite normal the include path is relative to the current directory where php is executed not relative to the php script which is executed ... isn't it ?