Jump to content

[SOLVED] DOCUMENT_ROOT


jaymc

Recommended Posts

I use $_SERVER['DOCUMENT_ROOT'] to check the path of a script however I have just realised if you run a script outside of apache, $_SERVER variable does not contain anything

 

So my question is, when running php script via cronjob or command line how can I retreive the document root of the file?

Link to comment
https://forums.phpfreaks.com/topic/162624-solved-document_root/
Share on other sites

Wait sorry it doesn't do what I need

 

<?
// this php file exists in /home/jay/live/www/scripts/file.php
// I want $dir to = /home/jay/live/www/scripts/
// not /home/jay/

include("/home/jay/global.php"); // this has $dir = dirname(__FILE__);

echo $dir;
?>

Link to comment
https://forums.phpfreaks.com/topic/162624-solved-document_root/#findComment-858337
Share on other sites

There is no good way to determine a DOCUMENT_ROOT in this situation. Your global.php is outside of your site's directory. You could always do this:

$dir = dirname(__FILE__).'/live/www/scripts/';

 

or how about:

$dir = dirname(realpath($_SERVER['SCRIPT_NAME']));

Link to comment
https://forums.phpfreaks.com/topic/162624-solved-document_root/#findComment-858633
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.