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

[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:
&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![/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.
#22

[eluser]Latavish[/eluser]
i totally forget about this post. I have a much better version of this script. i'll post tonight when I get off the 9 to 5.
#23

[eluser]hugle[/eluser]
[quote author="Latavish" date="1258663385"]i totally forget about this post. I have a much better version of this script. i'll post tonight when I get off the 9 to 5.[/quote]

Hello mate, how is it going with an update?Smile

thanks!
#24

[eluser]Unknown[/eluser]
I'm also really anxious to see your latest version of your script. I have been working on integrating a cool flash-based solution into a non-CI site. I would love to get that same type of interface working with CI. It sounds like that is what you have working but I'm not sure. I would also love to see a sample of how it looks/works. Do you have anything up that we could look at? Anyway thanks for your great contribution to the community
#25

[eluser]maria clara[/eluser]
hi to all,

im having an error with my upload script in CI. the image don't show off in the database and in the folder where it should be put in.

here's my script:
CONTROLLER:
Code:
$config['upload_path'] = './reports/module/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size']    = '100';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $this->load->library('upload', $config);
                
                $file_data = $this->upload->data();
                $file_name = $file_data['file_name'];
                
                    $fields = array(
                "module_id",
                            "module_name",
                "slug",
                "icon"=>$file_name,            
                            "report_file_name",
                            "sql_select",
                            "sql_filter",
                            "sql_order"
                            );

                    foreach ($fields as $field)
                    {
                        if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
                    }
                
                    $item = $this->input->post("item");
                    $rows = $this->input->post("row0");
                            
                    $data['item'] = $this->Reports->save($dt,$item,$rows);

MODEL:
Code:
function save($data,$item,$details) {
        if ($item == '') {
            $data['link'] = "reports/view";
            $this->db->trans_start();
            $this->db->insert('sec_reports', $data);
            $item = $this->db->insert_id();
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
        }
        else {
            $this->db->trans_start();
            $this->db->where('module_id', $item);
            $this->db->update('sec_reports', $data);
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
        }
        return $item;
    }

help me please..

regards,
kahtrina
#26

[eluser]Unknown[/eluser]
very thankyou for santiag0 and vik407 Smile
#27

[eluser]druid100[/eluser]
@santiag0 ... nice work, it's simple and works nearly flawlessly!

but you have to call

$this->upload->initialize($config);

before each

$this->upload->do_upload();

to avoid problems caused by internal states of the upload class.

@vik407

the double extension problem is avoided if you add the code as mentioned above.
#28

[eluser]Unknown[/eluser]
Hi I have a form with 2 text boxes and multiple files. The problem is that when I have 2 attachments The method that saves information from the text boxes running 2 times
(for each file).I know that the error comes from the cycle, but do not know how to fix it

Example:

FORM

title = TEST
desc = descript for test

file1 = test.doc
file2 = test2.doc

DB
id 1 TEST descript for test
id 2 TEST descript for test



Please help

Comments are the Bulgarian
Code:
foreach($_FILES as $key => $value)
           {

                         // Проверявам дали полетата са празни
                    if(!empty($value['name']))
                    {
                    $this->upload->initialize($config);

                    // АКО ИМА ГРЕШКИ
                if (!$this->upload->do_upload($key))
                {
                    $data['error'][$j] =  $this->upload->display_errors();
                    $j++;
                }
                else
                {
                    $this->load->model('Process_image');
                    
                   // КАЧЕНИТЕ ФАЙЛОВЕ
                    $file = $this->upload->data();
              
                $file = array('upload_data' => $this->upload->data());
               // Проверявам да ли файла е изображение
                $name = $file['upload_data']['is_image'];
        
                if(($name)){
                    // Ако е правя thumbnail
                 $this->Process_image->process_pic();

                }else{
                    //Aко не е го записвам в базата
                    //$this->Art_model->add_f();
                    //$this->Art_model->add();
                  
                }

                }
                }
                $this->Art_model->add();
                
              
        }
#29

[eluser]maxrosecollins[/eluser]
[quote author="Latavish" date="1258663385"]i totally forget about this post. I have a much better version of this script. i'll post tonight when I get off the 9 to 5.[/quote]

did you ever post the update?

Max
#30

[eluser]Unknown[/eluser]
Hi guys, im new to this and this thread helps me a lot..thank you!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB