简体   繁体   English

使用codeigniter上传多张图片

[英]multiple image upload using codeigniter

im having a page that will insert username, ID and the user must be able to upload upto 10 images . 我的网页上会插入用户名,ID,并且用户必须能够上传最多10张图片。

The main problem that im having is when it comes to uploading multiple images using codeigniter. 我遇到的主要问题是使用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. 如果用户选择上传少于10张图片(例如2张或5张),那么我该如何忽略该错误,提示尚未选择文件,并且仅传递已上传的图片。

     <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. 任何帮助将不胜感激。

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. 而是$this->upload->data('image')将是一个数组。

And then you can do: 然后您可以执行以下操作:

foreach($this->upload->data('image') as $image) {
   passItToTheDatabase(); // your custom function

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM