several forms in html with enctype = & ldquo; multipart / form-data & rdquo;

advertisements

I'm trying to send two forms, one with enctype="multipart/form-data" for file upload, the other without. my problem is only one of them is working. the submit button wont send two form.

What I've tried:

<?php
echo '<form method="post" action="' . $PHP_SELF . '">';

....

echo '<input type="submit" name="submit" value="Submit"><br>';
echo "</form>";

echo '<form action="' . $PHP_SELF . '" method="post" enctype="multipart/form-data">
      <label for="file">Filename:</label>
      <input type="file" name="file" id="file"><br>
      <input type="submit" name="submit" value="Submit"></form>';

if (isset($_FILES["file"]["name"])){
    $file_name = $_FILES['file']['name'];

    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Stored in: " . $_FILES["file"]["tmp_name"];
        move_uploaded_file($_FILES['file']['tmp_name'], '../images/' . $file_name);
    }
}
?>


This is how it works in HTML. You can only send one form at a time. The only workaround is to send all your data with just one form.