Welcome Guest, Not a member yet? Register   Sign In
How to upload several images at the same time ???
#1

[eluser]ludo31[/eluser]
hello , I would like to know how to upload several images at the same time , I know for one image and I can store it in database !! but my project is about shoes :
each chose have identifier (id_chaussure ) and we can attach it several images : so here is my viex file where we download image

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Bienvenue dans l'Image&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <h1>Bienvenue dans l'Image des chaussures </h1>
    
    &lt;?php
    
        // here the id_shoes
    
        if(isset($identifiant_chaussure))
        {
            echo 'identifiant:'.$identifiant_chaussure ;
        }
        
          
    ?&gt;
    
    
    
    
              &lt;?php echo form_open_multipart('site/do_upload'); ?&gt;
              
              &lt;?php echo form_label('Identifiant', 'chaussure'); ?&gt;<br/>
             &lt;?php echo form_input('identifiant', $identifiant_chaussure); ?&gt;<br/>
        
        
        
                 &lt;input type="file" name="userfile" size="20" /&gt; <br/>
                
                 &lt;?php echo form_button('ajouter','Ajouter'); ?&gt;
        
                    &lt;?php echo form_submit('envoi', 'Envoyer'); ?&gt;
                    
             &lt;?php echo  form_close(); ?&gt;
    
  
    
&lt;/body&gt;
&lt;/html&gt;

I add a button in order to add other upload form so when we click on it another
&lt;input type="file" name="userfile" size="20" /&gt; <br/>
must show .

Code:
&lt;?php echo form_button('ajouter','Ajouter'); ?&gt;

and my last question how to get after ??
in my controller

Code:
$identifiant_chaussure = $this->input->post('identifiant');
                  
                  
                //  echo ('identifiant '.$identifiant_chaussure) ;  exit ;
                  
                
                $config['upload_path'] = './image/';
  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';
                
                $config['encrypt_name'] = true ;
  
  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());
  
   $this->load->view('image_view', $error);
  }
  else
  {
   // $data = array('upload_data' => $this->upload->data());
                        
                        $data = $this->upload->data();
                        
                        
                        
                        // print_r($data);exit ;
  
   $this->load->view('upload_success', $data);

}

thanks
#2

[eluser]pickupman[/eluser]
You just create two file inputs, and check for them.
Code:
//View
&lt;?php echo form_open_multipart('site/do_upload');?&gt;

<p>
  &lt;?php echo form_label('File 1:', 'userfile');?&gt;<br/>
  &lt;?php echo form_upload('userfile');?&gt;
</p>
<p>
  &lt;?php echo form_label('File 2:', 'userfile1');?&gt;<br/>
  &lt;?php echo form_upload('userfile1');?&gt;
</p>
<p>
  &lt;?php echo form_submit('submit', 'Upload');?&gt;
</p>
&lt;?php echo form_close();?&gt;

//In controller
# Configure image library stuff here

//Probably want to check for uploaded file exists here

//Try upload userfile
if( ! $this->upload->do_upload('userfile') )
{
  $error = array('error' => $this->upload->display_errors());
}else{
  $data['userfile'] = $this->upload->data();
}

//Probably want to check for uploaded file in second input here

//Try upload userfile1
if( ! $this->upload->do_upload('userfile1') )
{
  $error = array('error' => $this->upload->display_errors());
}else{
  $data['userfile1'] = $this->upload->data();
}
#3

[eluser]pbflash[/eluser]
You could also create multiple upload inputs like this:

Code:
&lt;input type="file" name="userfile[]" size="20" /&gt;
&lt;input type="file" name="userfile[]" size="20" /&gt;
&lt;input type="file" name="userfile[]" size="20" /&gt;
&lt;input type="file" name="userfile[]" size="20" /&gt;
&lt;input type="file" name="userfile[]" size="20" /&gt;
&lt;input type="file" name="userfile[]" size="20" /&gt;

as many as you want.

Then in your controller use:

foreach ($userfile as $file)
{
    ...process file
}
#4

[eluser]Jason Stanley[/eluser]
You can also use the 'multiple' attribute on the file input tag. However this doesn't work on Internet Explorer.

The other option is to use something like swfupload. However this requires flash to run.
#5

[eluser]ludo31[/eluser]
Hello ,

I think the problem is the libraries/Upload.php , it doesn't accept userfile as an array

I mean when I try in view :

Code:
&lt;form action="http://localhost/CodeIgniter3/index.php/site/do_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data"&gt;        
       &lt;input type="file" name="userfile" size="20" /&gt; <br/>
       &lt;input type="submit" name="envoi" value="Envoyer"  /&gt;  

in controller

Code:
function do_upload()
{
  
  $this->load->helper('array');
  
  
  //var_dump($_FILES['userfile']);
  
  
  
  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';
  
  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());
  
   $this->load->view('upload_form', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());
  
   var_dump($data);exit;
  
   //$this->load->view('upload_success', $data);
  }
  
  
}

$data result

Code:
array
  'upload_data' =>
    array
      'file_name' => string '3146819611_358b2612c2_b2.jpg' (length=28)
      'file_type' => string 'image/jpeg' (length=10)
      'file_path' => string 'C:/wamp/www/CodeIgniter3/uploads/' (length=33)
      'full_path' => string 'C:/wamp/www/CodeIgniter3/uploads/3146819611_358b2612c2_b2.jpg' (length=61)
      'raw_name' => string '3146819611_358b2612c2_b2' (length=24)
      'orig_name' => string '3146819611_358b2612c2_b.jpg' (length=27)
      'client_name' => string '3146819611_358b2612c2_b.jpg' (length=27)
      'file_ext' => string '.jpg' (length=4)
      'file_size' => float 7.37
      'is_image' => boolean true
      'image_width' => int 100
      'image_height' => int 90
      'image_type' => string 'jpeg' (length=4)
      'image_size_str' => string 'width="100" height="90"' (length=23)

but when we change :
Code:
&lt;input type="file" name="userfile[]" size="20" /&gt; <br/>

Code:
A PHP Error was encountered

Severity: Warning

Message: is_uploaded_file() expects parameter 1 to be string, array given

Filename: libraries/Upload.php

Line Number: 161

You did not select a file to upload.

that 's all
#6

[eluser]Mauricio de Abreu Antunes[/eluser]
Create your own lib.
There are several ways to create your own lib, managing your upload error in your way. Smile
#7

[eluser]ludo31[/eluser]
may be the solution is here

http://www.mitesdesign.com/blog/tag/code-igniter
#8

[eluser]pbflash[/eluser]
I haven't tried uploading multiple images with CI yet. It sounds like the upload library will only accept one file at a time. You may need to create your own library to handle multiple uploads.




Theme © iAndrew 2016 - Forum software by © MyBB