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
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?