2012-03-26 60 views
0

如何做一个多文件上传的笨多文件上传笨

<input type="file" name="pic[]"> 
<input type="file" name="pic[]"> 
<input type="file" name="pic[]"> 

如何上传呢?使用do_upload功能

+1

请参阅http://stackoverflow.com/questions/9845872/codeigniter-uploading-multiple-files-with-one-input/9846065#9846065我几天前回答。 – Woxxy 2012-03-26 18:52:39

+1

你可以看到这篇文章的stackoverflow希望这可以帮助你http://stackoverflow.com/questions/1908247/codeigniter-multiple-file-upload – Pus 2012-03-26 18:58:48

回答

8

您可以上传任意数量的文件

$config['upload_path'] = 'upload/Main_category_product/'; 
$path=$config['upload_path']; 
$config['allowed_types'] = 'gif|jpg|jpeg|png'; 
$config['max_size'] = '1024'; 
$config['max_width'] = '1920'; 
$config['max_height'] = '1280'; 
$this->load->library('upload'); 

foreach ($_FILES as $key => $value) 
{ 
    if (!empty($key['name'])) 
    { 
     $this->upload->initialize($config); 
     if (!$this->upload->do_upload($key)) 
     { 
      $errors = $this->upload->display_errors(); 
      flashMsg($errors);  
     } 
     else 
     { 
      // Code After Files Upload Success GOES HERE 
     } 
    } 
} 

你可以看到有没有必要name属性的。

+0

它不适合我,所以我用代码从http://stackoverflow.com/questions/9903619/codeigniter-html5-trying-to-upload-multiple-images-at-once这对我很有用。 – 2013-09-09 11:53:18