Error: [function.include]: failed to open stream: No such fi

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
marlin
-


Joined: 01 Sep 2006
Posts: 7

PostPosted: Mon Oct 10, 2011 11:03 pm    Post subject: Error: [function.include]: failed to open stream: No such fi Reply with quote

The offending code:

include ($myInclude);

is contained in a general purpose function that can be called from any script in any directory. $myInclude can always be found in the same directory as the calling script. In this case, the calling script is in

//localhost/myAlias/

and

$myInclude = 'myInclude.inc';

I get the error message "Warning: include(myInclude.inc) [function.include]: failed to open stream: No such file or directory". I get the same message if I change the code to

include ('myInclude.inc');

However, if I point my browser to

http://localhost/myAlias/myInclude.inc

it loads fine, without of course executing php commands in the included file.

The problem only recently appeared after running the same scripts for years. I am running Abyss X1 (2.7) on a Windows XP 2nd Ed notebook. The problem occurs with both Firefox and IE. The problem has NOT appeared on my Windows Vista desktop or Windows 7 netbook or when uploaded to a Linux based hosting service.

Thank you
Back to top View user's profile Send private message Visit poster's website
marlin
-


Joined: 01 Sep 2006
Posts: 7

PostPosted: Tue Oct 11, 2011 12:14 am    Post subject: A Rube Goldberg solution Reply with quote

If I change the code to

$path = $_SERVER['REQUEST_URI'];
$path_parts = pathinfo($path);
$incl = $_SERVER['DOCUMENT_ROOT'].$path_parts['dirname'].'/'.$incl;
include ($incl);

In other words, it backs up to the root, adds the path, and finally the file name, bringing it back to where it started. Rube Goldberg to the rescue.
Back to top View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 295
Location: Chicago, IL

PostPosted: Sun Oct 23, 2011 2:25 am    Post subject: Reply with quote

That means that the root you're including isn't the same as the current root of the operating script.

i.e. You're including a file outside of the current folder (if you do that, you'll need a directory traversal)...

Also interesting to note:

Main PHP file Includes script A, and script A includes script B.

When you include file A into the main, it continues to use the main path, so including B would need to be relative to the main script's directory, not the include A's directory, which would just seem logical. This is all fine and dandy if all the main files, and all the includes are all in one folder, but that's usually not the case, so you hit weird snags like that on some folders and not on others.

What you're providing is an absolute path (though odd, since it is sourced from the request URI, but still)... This removes the need to resolved the path differences... Good rule of thumb is to specify the full path all the time.
_________________
Portfolio: Robert Lerner
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group