I am trying to upload multiple images. I am using Codeigniter and I know there is a built in file upload class but I am just experimenting with my custom made image upload library. I have provided the code below.
The problem I am facing with the following code is it is just uploading only one (the one that is selected at last in the form) image.
Could you please kindly tell me where I am doing wrong?
My Controller:
function img_upload(){
$this->load->library('image_upload');
$image1= $this->image_upload->upload_image('imagefile1');
$image2= $this->image_upload->upload_image('imagefile2');
$image3= $this->image_upload->upload_image('imagefile3');
echo $image1 ."<br>"; echo $image2;
}
application/libraries/image_upload.php (Custom made library)
function upload_image($image_info){
$image=$_FILES[$image_info]['name'];
$filename = stripslashes($image);
$extension = $this->getExtension($filename);
$extension = strtolower($extension);
$image_name=time().'.'.$extension;
$newname="support/images/products/".$image_name;
$uploaded = move_uploaded_file($_FILES[$image_info]['tmp_name'], $newname);
if($uploaded) {return $image_name; } else {return FALSE;}
}
My Form
<form id="myForm" enctype="multipart/form-data"
action="<?php echo base_url();?>add/img_upload" method="post" name="myForm">
<input type="file" name="imagefile1" size="20" /><br>
<input type="file" name="imagefile2" size="20" /><br>
<input type="file" name="imagefile3" size="20" /><br>
<br /><br />
<input type="submit" value="upload" />
</form>