How to upload two different image with two browse button and single submit button

I want to upload two images, one of the user and second of his ID, using one submit button using mysqli. Here is my HTML.

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  your image: <input type="file" name="img"><br/>
  your Id card: <input type="file" name="img2">
  <input type="submit" name="publish" value="upload">
</form>

</body>
</html>

All I know is to upload the single image at a time but what if want to upload these image into the database with single submit. I am not writing PHP because I don’t know how to do this. I can upload multiple images at a time using an array but I want to use this method. Is it possible to do with PHP??

PHP for single upload:

<?php
$dir = "uploads/";
$t_file = $dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($t_file,PATHINFO_EXTENSION));

if(isset($_POST["upload"])) {
    $check = getimagesize($_FILES["img"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
?>

The easiest way would be to repeat the code you have for img for img2.

you mean repeat the same code:

<?php
$dir = "uploads/";
$t_file = $dir . basename($_FILES["img2"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($t_file,PATHINFO_EXTENSION));

if(isset($_POST["upload"])) {
    $check = getimagesize($_FILES["img2"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
?>

http://php.net/manual/en/features.file-upload.multiple.php

<form action="file-upload.php" method="post" enctype="multipart/form-data">
  Send these files:<br />
  <input name="userfile[]" type="file" /><br />
  <input name="userfile[]" type="file" /><br />
  <input type="submit" value="Send files" />
</form>

Straight from the manual…

For instance, assume that the filenames /home/test/review.html and /home/test/xwp.out are submitted. In this case, $_FILES[‘userfile’][‘name’][0] would contain the value review.html, and $_FILES[‘userfile’][‘name’][1] would contain the value xwp.out. Similarly, $_FILES[‘userfile’][‘size’][0] would contain review.html’s file size, and so forth.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.