简体   繁体   中英

Enabling multiple image upload in codeigniter

I am trying to upload multiple images in codeigniter.

The following code consists of a image uploader, it only allow me to upload one image as the details of other images are not detected.

How can I go about enabling it to allow upload of multiple images?

<?php echo form_open_multipart('backendProduct/product_image_upload?item_id='.$item_id);?>
    <div class="input-group">
        <?php echo "item id is: "; echo $item_id;?>
        <?php echo form_upload(array('name'=>'userfile', 'class'=>'form-control'));?>
        <span class="input-group-btn">
            <button class="btn btn-primary" name="submit" type="submit"><i class="icon-upload"></i></button>
        </span>
    </div>

</form>

controller

foreach($post as $key=> $value)
            {
                //retrieve the $key that start with 'images_files'
                if (0 === strpos($key, 'images_files'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    //$images_files = $value;
                    $images_files = $value[1];
                    echo $images_files;
                }
                elseif(0 === strpos($key, 'images_alt'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    $images_alt = $value;
                }
                elseif(0 === strpos($key, 'images_caption'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    $images_caption = $value;
                    /*array_push($images, 
                        array(
                            ,,$value)
                    );*/
                }

try this

<input type="file" multiple name="userfile[]" size="20" />

and on your controller side, you can follow this

https://stackoverflow.com/a/11539061/4213701

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