CodeIgniter Forums

Full Version: Multiupload not cycle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to create a multi-upload function, but I can only upload one file.
The upload function does not cycle

View
PHP Code:
.....
.....
echo 
form_open_multipart('Upload');
echo 
'<br/>Upload file(s):<br />';
echo 
'<br />'.form_upload('files[]','','multiple');
echo 
'<br />'.form_upload('files[]','','multiple'); 
echo 
'<br />'.form_upload('files[]','','multiple');
echo 
'<br /><br />'.form_submit('submit','Upload');
echo 
form_close();
.....
..... 
Controller

PHP Code:
......
......
public function 
upload_do()
{
  $this->load->helper('form'); $data = array(); $messaggi='';
  $data['title'] = 'Multiple file upload';
  $number_of_files count($_FILES['files']['name']);
  $files $_FILES['files']; $errors = array();
  $this->load->library('upload');
  $config['upload_path'] = $this->session->userdata('upload');

  for ($i=0$i<$number_of_files$i++)
 
 {
   if($_FILES['files']['size'][$i]>0){
 
  $_FILES['files']['name'] = $files['name'][$i];
   $_FILES['files']['type'] = $files['type'][$i];
   $_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
   $_FILES['files']['error'] = $files['error'][$i];
   $_FILES['files']['size'] = $files['size'][$i];
 
  $this->upload->initialize($this->set_upload_options());
 
  if ($this->upload->do_upload('files'))
 
  {
    data['uploads'][$i] = $this->upload->data();
    $nome_encrypt $data['uploads'][$i]['file_name'];
    foreach($this->upload->data() as $dati){echo 'filedata: '.$dati'<br/>'; }
 
  }
    else
    
{
     echo 'error: '.$this->upload->display_errors();
     $data['upload_errors'][$i] = $this->upload->display_errors();
    }
 
 }
}
 .......
 .......


Help me Confused

If I remove $ _FILES ['files'][ 'size'] the cycle works, but does not upload any file.
Check your php.ini file, there are settings in there for uploading

Also you need to set these two in php.ini file for file sizes.

upload_max_filesize = 10M
post_max_size = 10M

These two should contain the same value.
PHP Code:
.
<
input type="file" name="files[]"  multiple />
<
input type="file" name="files[]"  multiple />
<
input type="file" name="files[]"  multiple />
.. 
Controller
PHP Code:
 $config['max_size'] = $this->_CI->config->item('max_size'); 
 
 $config['max_width'] = $this->_CI->config->item('max_width');
$config['max_height'] = $this->_CI->config->item('max_height');
$config['overwrite'] =$this->_CI->config->item('overwrite');
$config['encrypt_name'] = $this->_CI->config->item('encrypt_name');
$config['allowed_types']=$this->_CI->config->item('allowed_types');
$config['upload_path']=$this->_CI->config->item('dir_dispense').$path;
 
 $data = array(); $tot_file_esiste=0$messaggi='';
 
 $number_of_files count(array_filter($_FILES['files']['name']));
 
 $files $_FILES['files']; $errors = array();
 
 $this->load->library('upload' $config);
 
 $upload_path $this->_CI->config->item('dir_dispense').$path;
 
 for ($i=0$i<count($_FILES['files']); $i++) {
 
  if(empty($_FILES['files']['name'][$i])) continue;
 
  else{
 
      $_FILES['files']['name'] = $files['name'][$i];
 
      $_FILES['files']['type'] = $files['type'][$i];
 
      $_FILES['files']['tmp_name'] = $files['tmp_name'][$i];
 
      $_FILES['files']['size'] = $files['size'][$i];
 
      $_FILES['files']['error'] = $files['error'][$i];
            }
 
  if($_FILES['files']['error']==0)
 
  {
 
   $filename pathinfo($_FILES['files']['name'], PATHINFO_FILENAME);
 
   $filedim=byte_convert($_FILES['files']['size']);    $filest pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION);
 
   if($this->upload->do_upload('files'))      {
 
   $data['uploads'][$i] = $this->upload->data();
 
    $nome_encryptsubstr($data['uploads'][$i]['file_name'], 0, -4);
 
    $link=$this->config->item('link_disp').$path.$nome_encrypt;
 
    $dir_prof=nome_sicuro($this->session->userdata('professore'));
}
     if($filename==""||empty($filename)) continue;
..



If a line is empty, the upload operation stops
Why?