Welcome Guest, Not a member yet? Register   Sign In
Latavish's Multiple Image Upload with Thumbnail Generation
#16

[eluser]Santiag0[/eluser]
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:
&lt;?php
echo $this->session->flashdata('notice');
echo '<h3>Upload multiple photos</h3>';
echo form_open_multipart('multiupload');
?&gt;
  &lt;input type="file" name="p1" size="20" /&gt;
    &lt;input type="file" name="p2" size="20" /&gt;
    &lt;input type="file" name="p3" size="20" /&gt;
<button type="submit" name="send-photos" id="send-photos">Send</button>
&lt;/form&gt;

Enjoy and say 'thaks' if you find handy Wink

Thanks!


Messages In This Thread
Latavish's Multiple Image Upload with Thumbnail Generation - by El Forum - 04-24-2009, 09:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB