...

View Full Version : Failed to open stream, no such file or directory error



millsi80
09-14-2009, 12:17 AM
Hi,

I am getting 2 errors that appear twice in different places on the same page.



Warning: include(C:\Inetpub hosts\domain.com\httpdocs\HSRS\addcode.php) [function.include]: failed to open stream: Invalid argument in C:\Inetpub\vhosts\domain.com\httpdocs\folder\video.php on line 469

Warning: include() [function.include]: Failed opening 'C:\Inetpub hosts\domain.com\httpdocs\HSRS\addcode.php' for inclusion (include_path='.;./includes;./pear') in C:\Inetpub\vhosts\domain.com\httpdocs\seasons\video.php on line 469


This is part of the code that is causing the first group of errors:



$hm = "C:\Inetpub\vhosts\domain.com\httpdocs\HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm\addcode.php";


and for the second group, simply


<?php include("footer.php"); ?>


only instead of


Warning: include(C:\Inetpub hosts\domain.com\httpdocs\HSRS\addcode.php)


I get


Warning: include(footer.php)

Could someone explain these errors and maybe what I can do to fix them? PHP is not my strong point ;)

Thanks!

sajjad
09-14-2009, 07:04 AM
file:///c:/ use that

abduraooft
09-14-2009, 09:06 AM
Try changing
$hm = "C:\Inetpub\vhosts\domain.com\httpdocs\HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm\addcode.php"; to

$hm = $_SERVER['DOCUMENT_ROOT']."/HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm/addcode.php";

millsi80
09-15-2009, 01:29 AM
Thanks for the replies, but still nothing :(

This stopped working after I moved my site over to a different server, as far as I know, I setup the database properly....

abduraooft
09-15-2009, 06:56 AM
as far as I know, I setup the database properly.... Make it sure that there's no errors messages generated by the server in your javascript file.

SKDevelopment
09-15-2009, 11:00 AM
$hm = "C:\Inetpub\vhosts\domain.com\httpdocs\HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm\addcode.php";

1) If you use double quotes, you need to escape all "\" in your paths. E.g. like this:


$hm = "C:\\Inetpub\\vhosts\\domain.com\\httpdocs\\HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm\\addcode.php";

Or use single quotes:


$hm = 'C:\Inetpub\vhosts\domain.com\httpdocs\HSRS';
$hm2 = "http://domain.com/HSRS";
include $hm . '\addcode.php';

Small off-topic: please be very careful about what $hm contains. I do not see from your code where $hm comes from. So just in case: if it comes e.g. from $_GET, $_POST or $_COOKIE, it must be validated very strictly (in this case I would validate it very strictly despite it is in the path part, not file name). So that you could be sure no file injection attack against your script is possible.

2) As to the DOCUMENT_ROOT example, it is better be used like this:


$hm = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "HSRS";
$hm2 = "http://domain.com/HSRS";
include($hm . DIRECTORY_SEPARATOR . 'addcode.php');

(late edit: removed echo in the code above)
DIRECTORY_SEPARATOR would be "\" under Windows and "/" under *nix type operating systems.

To abduraooft: Please notice that the code you have posted above



$hm = $_SERVER['DOCUMENT_ROOT']."/HSRS";
$hm2 = "http://domain.com/HSRS";
include "$hm/addcode.php";

would give $hm equal to this:


C:\Inetpub\vhosts\domain.com\httpdocs/HSRS

under Windows. Since the OP has been clearly working under Windows (he has Windows paths), I think you made a typo in your post. I think you meant "\" instead of "/" before HSRS.

abduraooft
09-15-2009, 11:31 AM
Since the OP has been clearly working under Windows (he has Windows paths), I think you made a typo in your post. I think you meant "\" instead of "/" before HSRS.
Not sure what you mean, but I've an xampp under my drive G in my windows machine and for the statement
echo $_SERVER['DOCUMENT_ROOT']; I get an output like

G:/xampp/htdocs/mydir/mysubdir and I've been following that method without any issues(even when I deploy my code to a server running on a linux machine)

SKDevelopment
09-15-2009, 12:04 PM
I meant the following:

The OP has been working with Windows paths like this:


C:\Inetpub\vhosts\domain.com\httpdocs\HSRS

The code


$hm = $_SERVER['DOCUMENT_ROOT']."/HSRS";

would assign


C:\Inetpub\vhosts\domain.com\httpdocs/HSRS

to $hm in this particular case. Not in xampp I mean but with the paths the original poster has described.

I think you made a typo and considering his particular situation meant to use


$hm = $_SERVER['DOCUMENT_ROOT'] . '\HSRS';

instead.

To avoid such problem with slashes, I would suggest to use


$hm = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "HSRS";

which should give correct slashes under any OS.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum