PDA

View Full Version : php error



wmabear54
05-14-2004, 03:48 PM
Hi all

I am getting error in the php logs, when I call for the index.php that is made up of 3 inc's this is the error that I get.

[13-May-2004 14:53:29] PHP Warning: main(C:/apache2/htdocs/inc/header1.php): failed to open stream: No such file or directory in C:\apache2\htdocs\giftdealsgalore\index.php on line 2

[13-May-2004 14:53:29] PHP Warning: main(): Failed opening 'C:/apache2/htdocs/inc/header1.php' for inclusion (include_path='.;c:\apache2\php;c:\apache2\php\sma rty;c:\apache2\php\pear;c:\apache2\php\pear\pear') in C:\apache2\htdocs\giftdealsgalore\index.php on line 2

It's not that I don't understand that the inc dir. needs to be in the dir. of giftdealgalore it is according to the file structure at the command promt.

It appears to me that php looked for the inc here 'C:/apache2/htdocs/inc/header1.php' when it should have looked here
'C:/apache2/htdocs/giftdealsgalore/inc/header1.php'
everything works fine on the remote host this is on localhost.

any ideas

Mike

jestep
05-14-2004, 04:00 PM
What is the code you are using to call the files?

wmabear54
05-14-2004, 04:14 PM
Thanks Jestep

This is the code, and this has given me a idea that maybe calling for the code locally may be different than callin it remotelly I may not have local site set up right yet still very confusing. Think I will change what is below

<?php
include $_SERVER['DOCUMENT_ROOT']."/inc/header1.php";

include $_SERVER['DOCUMENT_ROOT']."/inc/leftcol.php";

include $_SERVER['DOCUMENT_ROOT']."/inc/rightcol.php";
?></div>
</div>
<div align="center">


/giftsgalore_1aaa.jpg</p>


</p>


</p>
</div>
</div>
</body>
</html>

to

<?php
include $_SERVER['DOCUMENT_ROOT']."/giftdealsgalore/inc/header1.php";

include $_SERVER['DOCUMENT_ROOT']."/giftdealsgalore/inc/leftcol.php";

include $_SERVER['DOCUMENT_ROOT']."/giftdealsgalore/inc/rightcol.php";
?></div>
</div>
<div align="center">


/giftsgalore_1aaa.jpg</p>


</p>


</p>
</div>
</div>
</body>
</html>


Do you think maybe that is it

Mike

wmabear54
05-14-2004, 04:29 PM
I changed it and that didn't work

Stuumped

jestep
05-14-2004, 04:33 PM
Try
include "./giftdealsgalore/inc/header1.php";

wmabear54
05-14-2004, 04:35 PM
I'll try it

Mike

ronniethedodger
05-14-2004, 04:35 PM
Try something like this:



<?php

$app_root_path = './';

include($app_root_path . 'inc/header1.php');
include($app_root_path . 'inc/leftcol.php');
include($app_root_path . 'inc/rightcol.php');
?>

wmabear54
05-14-2004, 04:48 PM
Hi Jestep

include "./giftdealsgalore/inc/header1.php"; Well that did work. Thanks

Hi Ron

I think I will try your way too a little later.

There still must be something wrong though, because I thought that I should have the same file structure for the remote and testing server.

Mike

ronniethedodger
05-14-2004, 05:42 PM
There still must be something wrong though, because I thought that I should have the same file structure for the remote and testing server.

The way I read your code is that it appeared that even though the file structure might be the same, your directory for /giftdealsgalore/ is one directory up from the root on your local server.

This is why I included the $app_root_path = './'; in my example to establish the current working directory to use as a reference point. No matter where you move the code now, it will always be based on the reference point. In other words...it will work in root/ and root/giftdealsgalore/ too.

jestep
05-14-2004, 05:56 PM
No matter where you move the code now, it will always be based on the reference point
I agree, this is why I always use this format in includes, I dont have to change the code no matter where the page happens to be.

wmabear54
05-14-2004, 06:14 PM
Yes Ron that's right I think that on the testing or localhost the doc root is in the wrong place. So what you are saying is that using $app_root_path = './'; in the inc file on the remote server and on the testing server will allow both to work properly. What my goal is, is to have the same exact files on the remote and testing (afraid I will upload the wrong set to one or the other) I want to mirrow my remote.

Mike

ronniethedodger
05-14-2004, 06:54 PM
Yes. Using a variable to store the current directory in will make the code portable.

I had the same problem you are going thru, and learned it the hard way. ;0)

I have a local server too ... and the directory for some of the sites are two or three levels up from the root. So I know that it works.

Example Webstractions Test Site (http://gonzo.ipupdater.com/webstractions/) and another test site (http://gonzo.ipupdater.com/gonzo/). Both sites use a path variable to establish what directory they are in. The code can be transferred to any other directory or the root of a server and still work.

wmabear54
05-14-2004, 07:05 PM
Thhanks Ron great info

Now I should be able to more on at a quicker pace and not worry about tweaking the local server to mimmick the remote as much.

Mike