[eluser]LynxCoder[/eluser]
[quote author="the_unforgiven" date="1334317009"]All images are uploaded to uploads folder the orginals.
Thumbs are uploaded to uploads/thumbs then the filename which will be for example:
aimage_thumb.png
whereas the orginal will just be aimage.png
soo what i want to do using this model i have you will see the commented out line is what i want to achieve:
Code:
function addItem(){
$data = array(
'category_id' => $this->input->post('categories'),
'customerNumber' => $this->input->post('customerNumber'),
'item_name' => $this->input->post('name'),
'item_description' => $this->input->post('desc'),
'item_price' => $this->input->post('price'),
'posted_by' => $this->input->post('customer'),
);
$image_data = $this->upload->data();
$data['item_img'] = $image_data['file_name'];
// So i presume i will need $data['item_img'] = $image_data['file_name']; again but with thumb in the $data not item_img but what will go inside the $image_data? if i put file_name again it just puts in the original image but i want it to store the thumb that was created.
$this->db->insert('items', $data);
}
[/quote]
Ah right ok. Well first thoughts are that I always look to minimise the amount of data i'm storing in the database where possible - the smaller the database size the better. In your case the thumbs and original images always have the same filename (just the thumbs have '_thumb' on the end, so I would just store the original filename in the database, then in your view file when you want the thumbnail to be displayed just use str_replace
FOR EXAMPLE:
Code:
<img src="<?php echo $img_path . str_replace('.jpg','_thumb.jpg',$data['item_img']);?>">
and that will display the thumbnail.
If you wanted to be really efficent and all your images are JPG files, you could even remove the .jpg from the original filename and just add it back in the view, so that you would use the following instead:
Code:
// remove the .jpg from the filename
$data['item_img'] = str_replace('.jpg','',$image_data['file_name']);
VIEW CODE:
// display the original image
<img src="<?php echo $img_path . $data['item_img'];?>.jpg">
// display the thumbnail
<img src="<?php echo $img_path . $data['item_img'];?>_thumb.jpg">
That would be my preferred option. Other than that - yes your good to go!
Rich