複数の画像をアップロードしようとしています。私は Codeigniter を使用しており、ファイルアップロードクラスが組み込まれていることは知っていますが、カスタムメイドの画像アップロードライブラリを試しているところです。以下のコードを提供しました。
次のコードで直面している問題は、1 つだけ (フォームで最後に選択されたもの) の画像をアップロードしていることです。
どこが間違っているのか教えてください。
私のコントローラー:
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 (自作ライブラリ)
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;}
}
マイフォーム
<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>