Reputation: 3139
I'm having some problems referencing a file on my website in a PHP script. Let's say the full path is
www.mydomain.com/img/peggy.jpg
I can't use relative addressing like in
../img/peggy.jpg
because the script is in an include file which is included in several files at different levels.
/img/peggy.jpg
doesn't seem to work either. How do I reference to an absolute path?
TIA
Steven
Upvotes: 0
Views: 412
Reputation: 5526
You could define(BASE_PATH, dirname(__FILE__))
in your index.php.
Then use $fileName = BASE_PATH . "/img/peggy.jpg";
Upvotes: 1
Reputation: 3139
Solved by writing the full path explicitly:
/home2/mydomain/public_html/img/peggy.jpg
Note to self: will have to edit this if I ever move to another hosting service. Even my current hosting service (Bluehost) may one day decide to rearrange its file structure.
Other solutions are still welcome!
Upvotes: 0
Reputation: 38308
$_SERVER['DOCUMENT_ROOT']
points to the absolute path of the current web root.
Upvotes: 0
Reputation: 55334
You would have to use dirname(__FILE__) . "/img/peggy.jpg"
.
You can use multiple, as well: dirname(dirname(__FILE__))
...
Upvotes: 0