diff options
-rw-r--r-- | phpfspot.class.php | 29 | ||||
-rw-r--r-- | phpfspot_img.php | 2 |
2 files changed, 26 insertions, 5 deletions
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!<br />\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() + } ?> diff --git a/phpfspot_img.php b/phpfspot_img.php index 5747b73..ce3731b 100644 --- a/phpfspot_img.php +++ b/phpfspot_img.php @@ -76,7 +76,7 @@ class PHPFSPOT_IMG { if(!$this->parent->getMD5($idx)) { $this->parent->gen_thumb($idx); } - $fullpath = $this->parent->cfg->base_path ."/thumbs/". $width ."_". $this->parent->getMD5($idx); + $fullpath = $this->parent->get_thumb_path($width, $idx); /* if the thumb file does not exist, create it */ if(!file_exists($fullpath)) { $this->parent->gen_thumb($idx); |