zembereck / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

Scenario in TimThumb where it fails to get the correct docRoot in the function calcDocRoot. #324

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This was reported to me so I'm passing it on...

TimThumb where it fails to get the correct docRoot in the function 
calcDocRoot.. Basically rather than add a bunch of additional logic to handle 
strange setups I define an optional global in timthumb-config.php and check for 
it in timthumb.php on line 800 Here is the new calcDocRoot function:

protected function calcDocRoot(){
if(!defined("TIM_DOCROOT")){
$docRoot = @$_SERVER['DOCUMENT_ROOT'];
if(!isset($docRoot)){ 
$this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting 
search 1.");
if(isset($_SERVER['SCRIPT_FILENAME'])){
$docRoot = str_replace( '', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 
0-strlen($_SERVER['PHP_SELF'])));
$this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: 
$docRoot");
} 
}
if(!isset($docRoot)){ 
$this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2.");
if(isset($_SERVER['PATH_TRANSLATED'])){
$docRoot = str_replace( '', '/', substr(str_replace('\', '', 
$_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
$this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: 
$docRoot");
} 
}
if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = 
preg_replace('//$/', '', $docRoot); }
} else {
$docRoot = TIM_DOCROOT; 
}
$this->debug(3, "Doc root is: " . $docRoot);
$this->docRoot = $docRoot;
}

you'll see it is checking for a constant called TIM_DOCROOT... Here is a sample 
definition:

define ('TIM_DOCROOT','D:Inetpubwwwsites');

if it isn't needed just comment that line out.

Original issue reported on code.google.com by shaza...@gmail.com on 20 Jan 2012 at 2:50

GoogleCodeExporter commented 9 years ago
Hi - this has existed since December 5th. The constant is called

LOCAL_FILE_BASE_DOCROOT

set that and you can override the docroot of the script

Original comment by BinaryMoon on 7 Feb 2012 at 1:56