terrible path 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

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

terrible path error

Post by Ree »

hi all, i'm having a hard time trying to fix the path error i recieve. i'll explain the file organization a bit.

the files of the site are all put in '/htdocs/stuff'. so, in that same directory i have a cfg.php file which contains:

Code: Select all

<?php
define('root', '/htdocs/stuff');
?>
i have a file switch_page_admin.php which is in '/htdocs/stuff/func' and i need to include it in index.php which is in '/htdocs/stuff/admin'. what i do is inlude cfg.php, and use the constant 'root' to indicate the path of switch_page_admin.php. here's how it looks in index.php:

Code: Select all

<?php
include('../cfg.php'); //since index.php is in '/htdocs/stuff/admin' and cfg.php is in '/htdocs/stuff'
include(root . '/func/switch_page_admin.php');
?>
i get (Warning: main(/htdocs/stuff/func/switch_page_admin.php): failed to open stream: No such file or directory) when i run index.php although i double checked - switch_page_admin.php is there (in '/htdocs/stuff/func'). now what do i do wrong here? i'm a true beginner so i probably missed something.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Are you sure /htdocs is in the root of the filesystem and not just the root of your home directory? is this a shared server?

This should tell you...

Code: Select all

echo realpath('./');
Wherever you put that PHP script will show you the full filesystem path to it ;)
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

yes, i'm sure '/htdocs' is the root dir. btw it's a local server on my pc. :)

the thingy you told me, it just showed me i have the dirs all indicated correct. now really, i don't get what's wrong...
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

If I undestood right your folderstructure is something like this:

Code: Select all

&#1111;htdocs]
  &#1111;stuff]
    &#1111;admin]
      index.php
    &#1111;/admin]
    &#1111;func]
      switch_page_admin.php
    &#1111;/func]
    cfg.php
  &#1111;/stuff]
&#1111;/htdocs]
And if it is, it works. Tested this myself. Are you absolutely sure, that all filenames are lowercase and spelled just as they are written here.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

wwwapu, that's exactly how the files are stored. i double checked upper and lowercase things, and it's all correct, all are lowercase, both in scripts and file system. you say it runs on your side well? what i find extremely weird is that the error says Warning: main(/htdocs/stuff/func/switch_page_admin.php): failed to open stream: No such file or directory in E:\Software\Server\Apache2\htdocs\stuff\admin\index.php on line 10 when /htdocs/stuff/func/switch_page_admin.php DOES exist.

maybe there's a php setting i should change? but i somehow doubt it since the settings are pretty much default. if you have any suggestions please let me know.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you forgot a $ for root... so include($root . 'whatever');


you migh also want to have a look at the "include_path" setting.
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

timvw wrote:you forgot a $ for root... so include($root . 'whatever');


you migh also want to have a look at the "include_path" setting.
No, it's a constant..
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

i have just checked the same on another pc, the same result. should i change include_path as suggested? and how? mine is commented in php.ini.
Post Reply