代码点火器:上传多个图像

时间:2012-05-29 12:17:46

标签: codeigniter-2

我的代码:

查看

<?php echo form_open_multipart('projects/create') ?>
<label for="pro_video">Project Image</label>
    <?php echo form_upload(array('name'=>'pro_image', 'type'=>'file', 'multiple'=>'multiple', 'accept'=>'image/*'))?>
<input type="submit" name="create_project" value="Create" />
</form>

控制器

    public function __construct()
        {
            parent::__construct();
            $this->load->library('image_lib');
            $this->load->helper(array('form', 'url', 'html'));
            $this->load->library('form_validation');
        }

public function create()
    {
    if( sizeof($_FILES['pro_image']) > 0 ){

        $config['upload_path'] = './test_upload/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';

        $this->load->library('upload', $config);

        $this->image_lib->initialize($config);

            for( $i = 0; $i < sizeof($_FILES['pro_image']['name']); $i++ ){

                   $this->upload->do_upload('pro_image');
            }
    }
}

但它上传了最后一张图片.. :(

on var_dump($ _ FILES):

array(1) {
  ["pro_image"]=>
  array(5) {
    ["name"]=>
    array(2) {
      [0]=>
      string(10) "Desert.jpg"
      [1]=>
      string(10) "Tulips.jpg"
    }
    ["type"]=>
    array(2) {
      [0]=>
      string(10) "image/jpeg"
      [1]=>
      string(10) "image/jpeg"
    }
    ["tmp_name"]=>
    array(2) {
      [0]=>
      string(23) "E:\wamp\tmp\phpA235.tmp"
      [1]=>
      string(23) "E:\wamp\tmp\phpA245.tmp"
    }
    ["error"]=>
    array(2) {
      [0]=>
      int(0)
      [1]=>
      int(0)
    }
    ["size"]=>
    array(2) {
      [0]=>
      int(845941)
      [1]=>
      int(620888)
    }
  }
}

1 个答案:

答案 0 :(得分:0)

感谢朋友们,我使用了HTML5 文件标记