View previous topic :: View next topic |
Author |
Message |
marlin -
Joined: 01 Sep 2006 Posts: 11
|
Posted: Mon Oct 10, 2011 11:03 pm Post subject: Error: [function.include]: failed to open stream: No such fi |
|
|
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 |
|
|
marlin -
Joined: 01 Sep 2006 Posts: 11
|
Posted: Tue Oct 11, 2011 12:14 am Post subject: A Rube Goldberg solution |
|
|
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 |
|
|
Toasty -
Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
|
Posted: Sun Oct 23, 2011 2:25 am Post subject: |
|
|
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. _________________ Audit the secure configuration of your server headers! |
|
Back to top |
|
|
|
|
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
|
|