I'm just wondering if there is a cleaner approach to how I've created my thumbnail URLs. Some of my Admin pages were loading as many as 60 full size images at once so wanted to load thumbnails instead (whose URLs arent stored in the DB):
Image URL: folder/folder/imagename.jpg
Thumb URL: folder/folder/thumbs/thumb_imagename.jpg
There can be upto 4 parent folders for an image.
Code:
// Get the image location from DB
$dbimg = $results[$i]['image'];
$imgurl = $dbimg;
// Work out the folder names (everything upto the last trailing slash)
$folder = substr($dbimg, 0, mb_strrpos ($dbimg , '/'));
//Get the last trailing slash and imagename.jpg
$newimgurl = strrchr($imgurl, '/');
// Add the thumbs folder name and thumb_prefix to the image name
$rawstring = $newimgurl;
$new_thumb = str_replace("/", "/thumbs/thumb_", $rawstring);
$domain = "images/uploads/".$folder."".$new_thumb."";
It works, but seems kinda longwinded for what Im trying to achieve. Can anyone offer a cleaner approach?  Thanks
|