From 4ff4a0e7adc87e654f6eefccdd2f43827bd06535 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Thu, 1 Nov 2007 10:42:46 +0000 Subject: issue73, new directory structure for thumbnails git-svn-id: file:///var/lib/svn/phpfspot/trunk@275 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- phpfspot.class.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'phpfspot.class.php') diff --git a/phpfspot.class.php b/phpfspot.class.php index b82fbee..723140f 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -292,7 +292,7 @@ class PHPFSPOT { } $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name']; - $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo); + $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo); if(!file_exists($orig_path)) { $this->_error("Photo ". $orig_path ." does not exist!
\n"); @@ -305,7 +305,7 @@ class PHPFSPOT { /* If the thumbnail doesn't exist yet, try to create it */ if(!file_exists($thumb_path)) { $this->gen_thumb($photo, true); - $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo); + $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo); } /* get f-spot database meta information */ @@ -755,7 +755,7 @@ class PHPFSPOT { $img_name[$rows][$cols] = htmlspecialchars($this->getPhotoName($photos[$i], 15)); $img_title[$rows][$cols] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0)); - $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]); + $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i]); if(file_exists($thumb_path)) { $info = getimagesize($thumb_path); @@ -1129,7 +1129,12 @@ class PHPFSPOT { foreach($resolutions as $resolution) { - $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5; + $thumb_sub_path = substr($file_md5, 0, 2); + $thumb_path = $this->cfg->base_path ."/thumbs/". $thumb_sub_path ."/". $resolution ."_". $file_md5; + + if(!file_exists(dirname($thumb_path))) { + mkdir(dirname($thumb_path), 0755); + } /* if the thumbnail file doesn't exist, create it */ if(!file_exists($thumb_path)) { @@ -1808,6 +1813,22 @@ class PHPFSPOT { } // extractTags() + /** + * returns the full path to a thumbnail + */ + public function get_thumb_path($width, $photo) + { + $sub_path = substr($this->getMD5($photo), 0, 2); + return $this->cfg->base_path + . "/thumbs/" + . $sub_path + . "/" + . $width + . "_" + . $this->getMD5($photo); + + } // get_thumb_path() + } ?> -- cgit v1.2.3-18-g5258