i have a php script that uploads an image, renames it to a random hash, creates folders based on the hash, stores the original image in the last created folder, and finally, creates 2 other thumbnails for it...
regular image... images/a3c/65c/297/108_a3c65c2974270fd093ee8a9bf8ae7d0b.jpg
thumbnail image... images/a3c/65c/297/108_a3c65c2974270fd093ee8a9bf8ae7d0b_t.jpg
smaller thumbnail... images/a3c/65c/297/108_a3c65c2974270fd093ee8a9bf8ae7d0b_sm.jpg
For each photo that is uploaded, it will store a new record in the DB which contains the photo id and this information
/a3c/65c/297/108_a3c65c2974270fd093ee8a9bf8ae7d0b
(notice how i didnt store the ".jpg" or "_t.jpg" etc)
Now in order for me to serve the images(i dont know if this is a good practice), Currently i have this php function that returns the image...
function get_image($image_id,$type = '')
{
$sql = "SELECT * FROM photos where photo_id = {$image_id}";
$query = $this->db->query($sql);
$r = $query->row();
$image = base_url().'images/'.$r->dir_1 . '/' . $r->dir_2 . '/' . $r->dir_3 . '/'.$image_id.'_'.$r->img_hash;
if($type == 'small')
return $image.'_sm.jpg';
if($type == 'reg_thumb')
return $image.'_t.jpg';
if($type == '' || $type == 'original')
return $image.'.jpg';
}
basically, i want to do something like twitter where the picture urls look like this
https://twimg0-a.akamaihd.net/profile_images/2392722244/blah.jpg
QUESTIONS...
- how can i achieve this type of url structure? Htaccess?
- Am I returning the images the right way?
- is what im doing safe, smart, and a good practice? if not is there a better method?
thanks!!