Welcome Guest, Not a member yet? Register   Sign In
Need help for: 2 image uploads with one form [SOLVED]
#1

[eluser]Christoph Rumpel[/eluser]
Hi,

ive been struggling with this problem the whole night and i just dont understand it. I have a simple form with one picture upload and resize function. That is working perfectly. But now i want a form with 2 file inputs and one submit button, so a user can upload 2 files. I just cant get it to work!

This is my code:

VIEW:
Code:
<?php
    if($this->session->userdata('logedin'))
    {
        // Kontrolliert ob es eine Fehlermeldung gibt
        if(isset($upload_data)) echo $upload_data;
                
         echo form_open_multipart('upload_c/do_upload');
    ?>
            <br />
            &lt;input type="file" name="userfile" size="20" /&gt;
            <br />
            &lt;input type="file" name="userfile1" size="20" /&gt;
            <br /><br />
            &lt;input type="submit" value="Bilder hochladen" /&gt;
            &lt;/form&gt;
            
            &lt;/body&gt;
            &lt;/html&gt;
    &lt;?php
                
        echo form_close();
    }
    else
    {
        echo "Um diese Seite zu besuchen, musst du eingeloggt sein!";
    }
?&gt;

CONTROLLER:

Code:
&lt;?php

class Upload_c extends CI_Controller {



    function do_upload()
    {
        
        
    // Upload- und resizefunktion
        // Test des Pfades
        //var_dump(is_dir('/Applications/MAMP/htdocs/gallery/'));
        //var_dump($_SERVER['SCRIPT_FILENAME']);
        
        $this->load->library('upload');
        $config['upload_path'] = './assets/img/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '200';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        
        
        //dadurch klappt der pfad (initialize)
        $this->upload->initialize($config);
        //$this->upload->do_upload("userfile1");

        if ( ! $this->upload->do_upload())
        {
        // Wenn der Upload NICHT funktioniert
                
            $data['upload_data'] =  $this->upload->display_errors();
            $data['title'] = 'Upload';
            $data['view'] = 'image/upload_v';
            $this->load->view('template',$data);
        }
        else
        {
        // Wenn der Upload funktioniert
            
            //$data für Weitergabe an sucess_view
            $data['upload_data'] = $this->upload->data();
            
            //infos über das upgeloadete file
            $data_upload_info = $this->upload->data();
            
            $this->load->library('image_lib', $config);
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data_upload_info['full_path'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 75;
            $config['height'] = 50;
            $config['ar_width'] = 75; //new config option
            $config['ar_height'] = 50; //new config option
            $config['new_image'] = './assets/img/thumbs/'.$data_upload_info['raw_name'].'_thumb.jpg';
        
            
            $this->image_lib->initialize($config);
            //ist eine zusätzliche library für image resize
            $this->image_lib->adaptive_resize();
            
            if ( ! $this->image_lib->adaptive_resize())
            {
                    echo $this->image_lib->display_errors();
            }
            else
            {
                //$this->load->view('image/upload_success_v', $data);
                $data['title'] = 'Upload';
                $data['view'] = 'image/upload_success_v';
                $this->load->view('template',$data);
            }
                
                
        }
        
            
            
    
    }
}
?&gt;

There are several sites in the Internet telling, it is simple to do what i want like: see example

In his example he is uploading the date with the field name:
Code:
$this->upload->do_upload("my_field_name_2");

But in my code this is not working. In my code i am never using the name of the input field and it works. Strange istn it??

I hope there is someone out there, who can help me. Not jsut me! There are a lot of people out there who are struggling with this issue an i hop we can fix it together!
thx
#2

[eluser]darrentaytay[/eluser]
Post removed - I was incorrect
#3

[eluser]InsiteFX[/eluser]
That Example is old code!
Code:
$filenew = rename("./avatars/" . $file_data['file_name'], "./avatars/newfile".$file_data['file_ext']);

// This line should be like this, change in the file array!
$filenew = rename("./avatars/" . $_FILE['file_name'], "./avatars/newfile".$_FILE['file_ext']);
You access the uploaded data using $_FILE['field_name']

InsiteFX
#4

[eluser]Christoph Rumpel[/eluser]
Thx for help. Ok now i know how to get the selected file, but where do i tell the uploadfunction, which file to upload and which upload settings are for which file?
And what is the rename for?
#5

[eluser]darrentaytay[/eluser]
I've made a simple demo with multiple uploads on my blog (it isn't finished but this post should help ya):

http://darrenonthe.net/2011/05/08/upload...deigniter/
#6

[eluser]Christoph Rumpel[/eluser]
Hi Darren,

that's exactly what i wanted to know. Thank you so much!!
Cant test it now, but i will implement it tomorrow.
Thx a lot!=)
greets from Austria
#7

[eluser]Christoph Rumpel[/eluser]
Works, great =)
THX
#8

[eluser]darrentaytay[/eluser]
No problem :-)




Theme © iAndrew 2016 - Forum software by © MyBB