首页 > 解决方案 > 多个上传图片的问题

问题描述

当客户单击选项 2 IMG 时,我有我想要的这个简单代码它向他显示两个输入上传图像,当他选择数字 1 IMG 选项时,只出现一个输入上传图像。并隐藏2个输入上传选项

请帮忙,我怎样才能以我遵循和搜索的这种格式执行此代码,但我做不到,也没有找到足够的解释

<div class="upload-btn-wrapper">
<label for="file" class="btns" id="file-label">
    Upload Image
 </label>
 <input type="file" class="file" action="" name="file" id="file" accept="image/*">
</div>
  <select id="X" name="X">
    <option value="1">1 IMG</option>
    <option value="2">2 IMG</option>
  </select>

他是与它一起使用的 php 代码

if (isset($_POST["submit"])) {
    
    $allowed_image_extension = array(
        "png",
        "jpg",
        "jpeg",
        "gif"
    );
    $uploadOk = 1;
    
    // Get image file extension
    $file_extension = strtolower(pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION));
    
    // Validate file input to check if is not empty
    if (! file_exists($_FILES["file"]["tmp_name"])) {
        $uploadOk = 0;
        $response = array(
            "type" => "error",
            "message" => "Choose image file to upload."
        );
    }    // Validate file input to check if is with valid extension
    else if (! in_array($file_extension, $allowed_image_extension)) {
        $uploadOk = 0;
        $response = array(
            "type" => "error",
            "message" => "Upload Valid Images. Only PNG, JPEG, JPG, GIF, Are Allowed."
        );
    }    // Validate image file size
    else if (($_FILES["file"]["size"] > 5000000)) {
        $uploadOk = 0;
        $response = array(
            "type" => "error",
            "message" => "Image Size Exceeds 5MB."
        );
    }  
    
       // Get Ip Cilent For Upload
       $upload_folder = "Uploads/";
       
       // boundary
       $semi_rand = md5(time());
       $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

       // headers for attachment
       $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

       // multipart boundary
        $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
        $message .= "--{$mime_boundary}\n";

       $content = '';
       $tmp_path = $_FILES["file"]["tmp_name"];
       if($tmp_path) {
                    $filename = $_FILES["file"]["name"];
                    $file = $upload_folder . $filename;
                    if(!copy($tmp_path, $file))
                    {
                                  $errors = '\n error while copying the uploaded file';
                    }
                    $file_size = filesize($file);
                    $handle = fopen($file, "rb");
                    $content = fread($handle, $file_size);
                    fclose($handle);
                    $content = chunk_split(base64_encode($content));
             }

       // if attachment
       if ($content) {
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"{$filename}\"\n" .
        "Content-Disposition: attachment;\n" . " filename=\"{$filename}\"\n" .
        "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";
        $message .= "--{$mime_boundary}\n";
        mail($send, $subject, $message, $headers);
        }
         
        //Vaildation Error Mag Before Redirection
        if ($uploadOk == 1) {
        header("Location:NEXT.PHP");
         }
     }

标签: javascriptphphtmljquery

解决方案


推荐阅读