note 70470 added to function.is-file
| From: | tatarynowicz at gmail dot com | Date: | Wed, 18 Oct 2006 02:35:48 +0000 |
| Subject: | note 70470 added to function.is-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118675@lists.php.net to get a copy of this message | ||
An easy way not to have to choose between hard-coding full paths and using relative paths is either
via this line:
<?php
// in the bootstrap file
define('DIR_ROOT', dirname(__FILE__));
// in other files, prefix paths with the constant
require(DIR_ROOT . '/relative/to/bootstrap.php');
?>
or if you have to use a relative path:
<?php
require(dirname(__FILE__) . '/relative/to/this_file.php');
?>
This way all your paths will be absolute, yet you can move the application anywhere in the
filesystem.
BTW, each successive call to dirname takes you one step up in the directory tree.
<?php
echo __FILE__;
// /www/site.com/public/index.php
echo dirname(__FILE__);
// /www/site.com/public
echo dirname(dirname(__FILE__));
// /www/site.com
?>
----
Server IP: 83.64.128.68
Probable Submitter: 87.206.164.46
----
Manual Page -- http://www.php.net/manual/en/function.is-file.php
Edit -- https://master.php.net/note/edit/70470
Del: integrated -- https://master.php.net/note/delete/70470/integrated
Del: useless -- https://master.php.net/note/delete/70470/useless
Del: bad code -- https://master.php.net/note/delete/70470/bad+code
Del: spam -- https://master.php.net/note/delete/70470/spam
Del: non-english -- https://master.php.net/note/delete/70470/non-english
Del: in docs -- https://master.php.net/note/delete/70470/in+docs
Del: other reasons-- https://master.php.net/note/delete/70470
Reject -- https://master.php.net/note/reject/70470
Search -- https://master.php.net/manage/user-notes.php