CodeIgniter Forums
Multiple file upload not working... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Multiple file upload not working... (/showthread.php?tid=3492)



Multiple file upload not working... - El Forum - 10-05-2007

[eluser]Jamongkad[/eluser]
Hey guys I'm having trouble uploading multiple files. I use the examples given by other CI gurus here but it doesn't seem to work. Here's my code...

View
Code:
<p>&lt;input type="file" name="userfile[]" SIZE="70" class='inputProjBox'/&gt;&lt;?php echo anchor('','Add',array('class'=>'addInputFields')); ?&gt;</p>

Model
I run a foreach loop cuz I don't know how many files the user is going to upload. Fortunately it runs if I upload the first file. But the subsequent files no banana..
Code:
function attachSprocketFile()
  {
   $config['upload_path'] = './sprocket_files/';
   $config['allowed_types'] = 'gif|jpg|png';
   $config['max_size'] = '2048';
   $config['max_width'] = '1024';
   $config['max_height'] = '768';
  
   $this->load->library('upload',$config);
  
    $build = array();
    for ($i=0; $i < count($_FILES['userfile']['name']); $i++) {
     $build['part' . $i]['type']   = $_FILES['userfile']['type'][$i];
     $build['part' . $i]['name']   = $_FILES['userfile']['name'][$i];
     $build['part' . $i]['type']   = $_FILES['userfile']['type'][$i];
     $build['part' . $i]['tmp_name']  = $_FILES['userfile']['tmp_name'][$i];
     $build['part' . $i]['error']   = $_FILES['userfile']['error'][$i];
     $build['part' . $i]['size']   = $_FILES['userfile']['size'][$i];
    }
    unset($_FILES['userfile']);
    $_FILES = $build;
  
  foreach($_FILES as $key=>$value){
    if(!$this->upload->do_upload($key))
    {
     $datas['error'] = $this->upload->display_errors();
     $datas['listings'] = $this->db->get('tag_listings');
     /*redirect('/sprocket/uploadFileForm/');*/
     $data['title'] = "Sprocket Fish: Upload Files";
     $data['header'] = $this->load->view('snippets/header.php','',TRUE);
     $data['content'] = $this->load->view('app/sprocket/upload_form.php',$datas,TRUE);
     $data['footer'] = $this->load->view('snippets/footer.php','',TRUE);
     $this->load->view('layout.php',$data);

    } else {
     $file = $this->upload->data();
     $this->load->library('image_lib');
    
     $config['image_library'] = 'GD';
     $config['source_image'] = './sprocket_files/'.$file['file_name'];
     $config['new_image'] = './sprocket_files_thumbs/'.$file['file_name'];
     $config['create_thumb'] = FALSE;
     $config['maintain_ratio'] = TRUE;
     $config['width'] = 75;
     $config['height'] = 50;
     $this->image_lib->initialize($config);
     $this->image_lib->resize();
    
     $config2['image_library'] = 'GD';
     $config2['source_image'] = './sprocket_files/'.$file['file_name'];
     $config2['new_image'] = './sprocket_files_resized/'.$file['file_name'];
     $config2['create_thumb'] = FALSE;
     $config2['maintain_ratio'] = TRUE;
     $config2['width'] = 367;
     $config2['height'] = 287;
    
     $this->image_lib->clear();
     $this->image_lib->initialize($config2);
     $this->image_lib->resize();
    
     $this->insertSprocketData();
    }
   }
  }

Thanks!


Multiple file upload not working... - El Forum - 10-06-2007

[eluser]Jamongkad[/eluser]
Anyone....?


Multiple file upload not working... - El Forum - 10-06-2007

[eluser]Arjen van Bochoven[/eluser]
[silly remark removed]

What does the output give you?


Multiple file upload not working... - El Forum - 10-06-2007

[eluser]llbbl[/eluser]
I highly recommend reading this article on secure file uploads.


www.scanit.be/uploads/php-file-upload.pdf


but it could be something silly like forgetting the multipart stuff in the &lt;form&gt; tag.


Multiple file upload not working... - El Forum - 10-07-2007

[eluser]Jamongkad[/eluser]
Oh no that's my fault! of course I have the &lt;form&gt; tag included. What I posted was a snippet of html. Basically it uploads the first file but the subsequent files do not upload.


Multiple file upload not working... - El Forum - 11-06-2007

[eluser]kbauman[/eluser]
This question has been asked before, and I believe the answer is to use:

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

for each additional time you need to utilize the class.