[eluser]Unknown[/eluser]
[quote author="Santiag0" date="1240604670"]The original code not work for me, but here is my
simplified working adaptation
Code:
class multiupload extends Controller
{
function index()
{
$config['upload_path'] = './content/img/photos';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048'; //2 meg
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->load->library('image_lib');
//Upload error flag
$error = FALSE;
foreach($_FILES as $key => $value)
{
if( !empty($value['name']))
{
if ( $this->upload->do_upload($key) )
{
$uploaded = $this->upload->data();
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $uploaded['full_path'];
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_tn';
$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
$config['width'] = 175;
$config['height'] = 175;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
$imagename = $uploaded['file_name'].'_tn'.$uploaded['file_ext'];
$timestamp = time();
//Add Pic Info To Database
$this->db->set('file', $imagename);
//$this->db->set('date', $timestamp);
//Insert Info Into Database
$this->db->insert('photos');
}
else
{
$error = TRUE;
}
}
}
//If we have some error...
if($error) $this->session->set_flashdata('notice', '<div class="error icon"><ol>'.$this->upload->display_errors('<li>','</li>').'</ol></div>');
else $this->session->set_flashdata('notice', '<p class="success icon">¡Success!</p>');
//Call the view
$this->load->view('upload_photos');
}
}
View file
Code:
<?php
echo $this->session->flashdata('notice');
echo '<h3>Upload multiple photos</h3>';
echo form_open_multipart('multiupload');
?>
<input type="file" name="p1" size="20" />
<input type="file" name="p2" size="20" />
<input type="file" name="p3" size="20" />
<button type="submit" name="send-photos" id="send-photos">Send</button>
</form>
Enjoy and say 'thaks' if you find handy
Thanks![/quote]
This code works great BUT must be correct the
Code:
$imagename = $uploaded['file_name'].'_tn'.$uploaded['file_ext'];
variable because produce duplicate extension (image.jpg_tn.jpg) in the saved image name.
The little fix is:
Code:
$imagename = substr($uploaded['file_name'], 0, -4)."_tn".$uploaded['file_ext'];
i search for a better way to do the last code but im very very tired now so... if someone knows is time to share :-)
Bye.