doubian6241 2011-10-18 14:19
浏览 59
已采纳

使用codeigniter进行多个图像上传

im having a page that will insert username, ID and the user must be able to upload upto 10 images .

The main problem that im having is when it comes to uploading multiple images using codeigniter.

  1. can someone suggest me how can i pass each image path of each individual image to the array so i can pass it to the database.

  2. and if the user selects to upload less than 10 images, like 2 or 5 then how can i ignore the error that says a file hasn't been selected and jst pass only the images that has been uploaded.

    <form method="post" action="uploader/go" enctype="multipart/form-data">
    <input name="username" type="text" /><br />
    <input name="nid" type="text" /><br />
    <input type="file" name="image1" /><br />
    <input type="file" name="image2" /><br />
    <input type="file" name="image3" /><br />
    <input type="file" name="image4" /><br />
    <input type="file" name="image5" /><br />
    <input type="file" name="image6" /><br />
    <input type="file" name="image7" /><br />
    <input type="file" name="image8" /><br />
    <input type="file" name="image9" /><br />
    <input type="file" name="image10" /><br />
    <input type="submit" name="go" value="Upload!!!" />
    </form>
    

sample controller

$image_data=array('image_info' => $this->upload->data('image')); 
$image_path=$image_data['image_info']['full_path'];

$data =array(
            'id'=>uniqid('id_'),
                    'nID'=>$this->input->post('nid'),
            'username'=>$username,
            'image1'=>$image_path
}

any help will be appreciated.

  • 写回答

1条回答 默认 最新

  • dongyang5716 2011-10-18 14:29
    关注

    change the input names to:

    <input type="file" name="image[1]" /><br />
    <input type="file" name="image[2]" /><br />
    <input type="file" name="image[3]" /><br />
    

    instead and $this->upload->data('image') will be an array.

    And then you can do:

    foreach($this->upload->data('image') as $image) {
       passItToTheDatabase(); // your custom function
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题