我想上传多个图像。我使用Codeigniter,我知道有一个内置的文件上传类,但我只是试验我自定义的图像上传库。我已经提供了下面的代码。试图上传多个图像,但它只上传一个
我面对的问题是下面的代码是只上传一个(最后选择的形式)图像。
请问您能否告诉我我在做什么错?
我的控制器:
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;
}
应用程序/库/ 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>
您是否尝试打印生成的文件名,以查看它是否每次都覆盖图像? –
是的,我试过了,它显示两次相同的文件名。谢谢 –
小文件呢?我曾经有过类似的问题,因为我上传的文件在哪里大到最大限度。 – bottleboot