我正在处理我的项目我想用单一形式上传图像,但我有两个输入字段。我希望当我在提交时在两个输入字段中选择两个图像时我希望我的两个文件都存储在文件夹中我向您展示了我的代码,但是使用此代码,我只获取一个图像。我想要我上传的两张图片。我的形式看起来像这样关于多个文件以单一形式上传
Here is my code:
public function upload_creative_workshop_image($post, $files){
//print_r($files); die;
$allowedExts= array("jpeg", "jpg", "png", "gif");
$temp = explode(".", $files["image1"]["name"]);
$extension = end($temp);
if ((($files["image1"]["type"] == "image/jpeg") //check image is mp3
|| ($files["image1"]["type"] == "image/gif") //check image is mp4
|| ($files["image1"]["type"] == "image/jpg") //check image is jpg
|| ($files["image1"]["type"] == "image/png")) //check image is png
&& ($files["image1"]["size"]) //check if image size is below 6MB
&& in_array(trim($extension), $allowedExts)) //check the extensions also
{
if($files["image1"]["error"] > 0){
echo $files["image1"]["error"];
}
else{
$filename = $files["image1"]["name"];
$upload= move_uploaded_file($files["image1"]["tmp_name"], $this->img_path.$filename);
//print_r($upload); die;
if($upload){
//$this->store_image_indb($filename, $post);
}
}
}else{
echo "<h1>please upload image only</h1>";
}
}
你必须调用你想要上传的每个图像的函数。在这种情况下,您的输入字段应具有不同的名称,如'image1'和'image2'。 **但是**我所要做的就是让输入字段变为多个,然后用'$ files'数组中的图像调用一次函数。为此,你必须在你的函数中添加一个循环。 – trpx
是啊我有两个字段是这样的不同名称: – kulu
”> – kulu