Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Altering Image URLs retrieved from mysql
Old 04-19-2010, 10:18 AM Altering Image URLs retrieved from mysql
downliner's Avatar
Extreme Talker

Posts: 208
Location: Orkney
Trades: 1
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
__________________

Please login or register to view this content. Registration is FREE
downliner is offline
Reply With Quote
View Public Profile Visit downliner's homepage!
 
 
Register now for full access!
Old 04-19-2010, 08:28 PM Re: Altering Image URLs retrieved from mysql
Extreme Talker

Posts: 246
Trades: 3
How about:

PHP Code:
    // Get the image location from DB
    
$dbimg $results[$i]['image'];

    
$domain "images/uploads/".dirname($dbimg)."/thumbs/thumb_".basename($dbimg); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Altering Image URLs retrieved from mysql
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10366 seconds with 12 queries