mennake/minify

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

Opened this issue · 0 comments

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