php - understanding relative paths and absolute paths -


wondering why php keeps telling me file doesnt exist when does.

this code , error

    require_once('/book/admin/bin/class/db.class.php'); 

error , stack trace

   warning: require_once(/book/admin/bin/class/db.class.php) [function.require-once]: failed open stream: no such file or directory in c:\wamp\www\book\forms\add.php on line 3     call stack     #   time    memory  function    location     1   0.1479  408440  {main}( )   ..\add.php:0 

this happens lot , want rectify annoying reoccurring problem. there way can set web server read root of site i'm asking too? or misunderstanding happening.

this how directory structure looks.

using wamp server

c:\wamp\www\book <- site root c:\wamp\www\book\forms <- add.php located c:\wamp\www\book\admin\bin\class\db.class.php 

why can not use filepath "/book/bin/"

thanks, c

absolute paths on windows starts drive letter. can use

require_once 'c:\wamp\www\book\admin\bin\class\db.class.php'; 

or can use relative path.

to see path "start out" @ use getcwd(); directory script "starts", e.g. directory index.php located.

echo getcwd(); 

you can require files relative dir.

however, suggest set define constant called application_dir or , build links that.

define('application_dir', 'c:\wamp\www\book'); require_once application_dir.'\admin\bin\class\db.class.php'; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -