why am I getting a 'failed to open stream error'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

why am I getting a 'failed to open stream error'

Post 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,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in due time... not that any one used it much when it was there... :roll:
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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') ;?>
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

try adding the ./ like i put in your code... :)
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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...
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

but if I type in the direct path to the footer file, it displays

http://localhost/SSI/footer.htm
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

good then try :
realpath('http://localhost/SSI/footer.htm');
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how about....

Code: Select all

require( $_SERVER['DOCUMENT_ROOT'] . 'SSI/whatever.file' );
;)
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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.
Post Reply