Page 1 of 2
why am I getting a 'failed to open stream error'
Posted: Wed Mar 16, 2005 11:16 am
by bruceg
when I preview my file I am getting a 'failed to open stream, so such file or directory' error for the follow code:
the code is <?php require('images/Rotating_Header/rotating-header-home.php'); ?>
the file is on the server and the directory structure is correct.
Any suggestions? New to PHP, but very familiar with ASP.
thanks,
Posted: Wed Mar 16, 2005 11:34 am
by feyd
use
realpath() on the path you are passing to the function to see where it's trying to open it. Remember that case matters
Moved to PHP - Code.
Posted: Wed Mar 16, 2005 11:49 am
by bruceg
thanks for the reply. I am pretty new to php so I am not sure where the
$real_path = realpath
would go in my code mentioned
Posted: Wed Mar 16, 2005 1:12 pm
by hongco
Code: Select all
$realpath = realpath('images/Rotating_Header/rotating-header-home.php');
feyd: could you add the button for php code to the BBcode, that would be very helpful

Posted: Wed Mar 16, 2005 1:55 pm
by feyd
in due time... not that any one used it much when it
was there...

Posted: Wed Mar 16, 2005 2:57 pm
by bruceg
I don't think I am doing this right for an include file because it's not working. I have:
Code: Select all
<?php
$realpath = realpath('SSI/rotating-header.htm') ;
?>
don't I still need to have the require in their somewhere?
Posted: Wed Mar 16, 2005 3:51 pm
by infolock
is the SSI directory in the root directory of which the script resides?
if so, try this.
Code: Select all
<?php $realpath = realpath('./SSI/rotating-header.htm') ;?>
Posted: Wed Mar 16, 2005 4:09 pm
by bruceg
yea, for instance with my footer I am now using
<?php $realpath = realpath('SSI/footer.htm'); ?>
the footer info. is in a folder called 'SSI' which is at the root level.
when I display in the browser I no longer get an error, but nothing shows up where my footer code is supposed to be.
Posted: Wed Mar 16, 2005 4:13 pm
by infolock
try adding the ./ like i put in your code...

Posted: Wed Mar 16, 2005 4:24 pm
by bruceg
tried it exactly the way you have it and it doesn't work either.
the file being included doesn't have to be .php does it?
Posted: Wed Mar 16, 2005 4:25 pm
by infolock
then the path you are trying to access the file at is incorrect. that's the only thing that could cause it not to work.
i'm assuming that the page you are trying to access is either on localhost or on a website. instead of realpath('SSI/footer.htm'); try
realpath('
http://www.mysite.com/SSI/footer.htm'); cuz it sounds to me like the directory you are trying to access does not reside in the same folder that the script is in...
Posted: Wed Mar 16, 2005 4:29 pm
by bruceg
but if I type in the direct path to the footer file, it displays
http://localhost/SSI/footer.htm
Posted: Wed Mar 16, 2005 4:30 pm
by infolock
Posted: Wed Mar 16, 2005 4:33 pm
by feyd
how about....
Code: Select all
require( $_SERVER['DOCUMENT_ROOT'] . 'SSI/whatever.file' );

Posted: Wed Mar 16, 2005 4:44 pm
by bruceg
thanks for the assistance guys, but it does doesn't work.
<?php $realpath = realpath('
http://localhost/SSI/footer.htm');?>
gets me blank space and
<?php require( $_SERVER['DOCUMENT_ROOT'] . 'SSI/footer.htm' ); ?>
gets me errors
Notice: Undefined index: DOCUMENT_ROOT in c:\inetpub\wwwroot\Administration\Staff_Appreciation_Awards.php on line 219
Warning: main(SSI/footer.htm): failed to open stream: No such file or directory in c:\inetpub\wwwroot\Administration\Staff_Appreciation_Awards.php on line 219
Fatal error: main(): Failed opening required 'SSI/footer.htm' (include_path='.;c:\php4\pear') in c:\inetpub\wwwroot\Administration\Staff_Appreciation_Awards.php on line 219
I have the document in another folder than the include file. Is this causing the problem? I would rather keep the structure the way I have it.