php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30437 include fails to open file from parent directory of include path
Submitted: 2004-10-14 18:23 UTC Modified: 2005-04-05 17:13 UTC
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: gabe at mudbuginfo dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.9 OS: linux 2.4.26
Private report: No CVE-ID: None
 [2004-10-14 18:23 UTC] gabe at mudbuginfo dot com
Description:
------------
This site prepends the full path to the site's directory 
for site-specific include files with the following code 
in the file /files/client/
global_fellowship_search/proto1/include/init.php

$site_include_path = dirname(__FILE__);
$sys_include_path = ini_get('include_path');
ini_set('include_path', $site_include_path . ':' .  
$sys_include_path);

which creates an include path of '/files/
client/global_fellowship_search/proto1/include:.:/usr/
local/lib/php:/usr/local/lib/mis:/usr/local/lib/
eclipse'

When attempting to include the file /files/
client/global_fellowship_search/proto1/mail/
forgot_pass.mail relative to the site's prepended 
include directory with "include_once '../mail/
forgot_pass.mail';", PHP fails to find the file.  
Supplying an absolute path to the file works.  It just 
seems like PHP will not respect crawling up a '..' 
parent directory link for any path within the 
include_path except for '.'

Note that this code was placed in the 'index2.php' file 
just for simplicity in demonstration; in implementation 
this inclusion code is held within another file in the 
include/ directory which is included several different 
directory levels.

Reproduce code:
---------------
(Within /files/client/
global_fellowship_search/proto1/index2.php)

include_once '../mail/forgot_pass.mail';

Expected result:
----------------
Inclusion of /files/client/
global_fellowship_search/proto1/mail/forgot_pass.mail

Actual result:
--------------
Warning: main(../mail/forgot_pass.mail): failed to open 
stream: No such file or directory in /files/client/
global_fellowship_search/proto1/index2.php on line 5

Warning: main(): Failed opening '../mail/
forgot_pass.mail' for inclusion (include_path='/files/
client/global_fellowship_search/proto1/include:.:/usr/
local/lib/php:/usr/local/lib/mis:/usr/local/lib/
eclipse') in /files/client/global_fellowship_search/
proto1/index2.php on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-14 22:06 UTC] gabe at mudbuginfo dot com
Note, open_basedir is not set anywhere for this site.
 [2004-10-14 22:22 UTC] gabe at mudbuginfo dot com
Easier test case:

Say for example, your include path is: /usr/local/lib/
php (most people have this or something similar)

<?php
echo "including normal DB\n";
include 'DB.php';
echo "including ../php DB\n";
include '../php/DB.php';
?>

The second include statement will fail with:
including normal DB
including ../php DB

Warning: main(../php/DB.php): failed to open stream: No 
such file or directory in /tmp/x.php on line 5

Warning: main(): Failed opening '../php/DB.php' for 
inclusion (include_path='.:/usr/local/lib/php:/usr/
local/lib/mis:/usr/local/lib/eclipse') in /tmp/x.php on 
line 5
 [2004-11-27 16:46 UTC] tony2001@php.net
Same as #30881, which is already documented.
 [2004-12-02 16:07 UTC] gabe at mudbuginfo dot com
Bug is different from 30881:

This bug does not refer to the CLI SAPI, and refers to 
files from the include_path and not the current working 
directory.

Prehaps the documentation should be updated to mention 
that when including a file in a parent directory (eg: 
'../blah.php'), paths within the  include_path will not 
be searched.
 [2004-12-02 16:12 UTC] tony2001@php.net
Making it documentation problem then.
 [2005-04-05 17:13 UTC] vrana@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Documentation of bug #30881 covers also this one.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 28 03:01:29 2024 UTC