简体   繁体   中英

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 .

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.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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