mmraja83 / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

$_SERVER['DOCUMENT_ROOT'] for file path is unreliable #327

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
After updating a clients website and uploading it to the server it did not 
display any pages. The website is hosted on a shared hosting plaform 
(pcextreme.nl). 

After some searching I found the problem to be with the minify library. The 
path to the files could not be resolved. 
I discovered that the variable $_SERVER was used to set the full path of the 
requested files. Turns out that this method is unreliable as it does not always 
return the correct path. In my case it returned the path to apache and not the 
root of the website.

Solution:
I placed the following code in the main index.php and it now works as expected.

if( ! defined('SELF') ) {
    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
}
if( ! defined('SELF_DIR') ) {
    define('SELF_DIR', str_replace(SELF, '', __FILE__));
}
if( ! defined('ROOT') ) {
    define('ROOT', dirname(SELF_DIR));
}
$_SERVER['DOCUMENT_ROOT'] = ROOT;

Original issue reported on code.google.com by mgl.webs...@gmail.com on 12 Dec 2014 at 8:56