From 324ed66eae6ca7d877d2e8eeebed8339229cfcc2 Mon Sep 17 00:00:00 2001 From: Tony Lambregts Date: Wed, 27 Jul 2005 02:10:56 +0000 Subject: [PATCH] Fix situation where AppDB is not at DocumentRoot --- include/image.php | 3 +-- include/incl.php | 8 ++++++-- include/screenshot.php | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/image.php b/include/image.php index c386dcb..e44ea6c 100644 --- a/include/image.php +++ b/include/image.php @@ -21,8 +21,7 @@ class Image { */ function Image($sRelativePath) { - $this->file = $_SERVER['DOCUMENT_ROOT'].$sRelativePath; - + $this->file = appdb_fullpath($sRelativePath); $info = @getimagesize($this->file); if( empty($info) ) diff --git a/include/incl.php b/include/incl.php index 68138db..49f94db 100644 --- a/include/incl.php +++ b/include/incl.php @@ -36,9 +36,13 @@ function apidb_fullurl($path = "") return BASE.$path; } -function apidb_fullpath($path) +function appdb_fullpath($path) { - return $_SERVER['DOCUMENT_ROOT'].BASE.$path; + /* IE: we know this file is in /yyy/xxx/include, we want to get the /yyy/xxx + /* so we call dirname on this file path twice */ + $fullpath = dirname(dirname(__FILE__))."//".$path; + /* get rid of potential double slashes due to string concat */ + return str_replace("//", "/", $fullpath); } diff --git a/include/screenshot.php b/include/screenshot.php index 8e42538..8e243ab 100644 --- a/include/screenshot.php +++ b/include/screenshot.php @@ -134,7 +134,7 @@ class Screenshot { { $this->oScreenshotImage->delete(); $this->oThumbnailImage->delete(); - unlink($_SERVER['DOCUMENT_ROOT']."/data/screenshots/originals/".$this->iScreenshotId); + unlink(appdb_fullpath("/data/screenshots/originals/".$this->iScreenshotId)); if(!$bSilent) $this->mailMaintainers(true); } @@ -208,7 +208,7 @@ class Screenshot { } $this->oThumbnailImage->make_thumb(0,0,1,'#000000'); // store the image - $this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/thumbnails/".$this->sUrl); + $this->oThumbnailImage->output_to_file(appdb_fullpath("/data/screenshots/thumbnails/".$this->sUrl)); // now we'll process the screenshot image for watermarking // load the screenshot @@ -217,7 +217,7 @@ class Screenshot { // resize the image $this->oScreenshotImage->make_full(); // store the resized image - $this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl); + $this->oScreenshotImage->output_to_file(appdb_fullpath("/data/screenshots/".$this->sUrl)); // reload the resized screenshot $this->oScreenshotImage = new Image("/data/screenshots/".$this->sUrl); if(!$this->oScreenshotImage->isLoaded()) return false; @@ -225,7 +225,7 @@ class Screenshot { // add the watermark to the screenshot $this->oScreenshotImage->add_watermark($watermark->get_image_resource()); // store the watermarked image - $this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl); + $this->oScreenshotImage->output_to_file(appdb_fullpath("/data/screenshots/".$this->sUrl)); return true; } @@ -321,7 +321,7 @@ function get_screenshot_img($iAppId = null, $iVersionId = null) } if(!$hResult || !mysql_num_rows($hResult)) { - $sImgFile = '
No Screenshot
'; + $sImgFile = '
No Screenshot
'; } else { $oRow = mysql_fetch_object($hResult);