Search code examples
phphtmlformsfile-upload

Why does PHP not GET the form input from this HTML form?


<form method="post" enctype="multipart/form-data" name="formUploadFile">      
<label>Select files to upload:</label>
<input type="file" name="files[]" multiple="multiple" /><br>
IF you didn't add tags in the image titles your can add them here "," seperated eg tagone,tagtwo,tagthree,tagfour <br> 
<input type="text" name="Tags"><br>
<input type="submit" value="Upload File" name="btnSubmit"/>
</form>

<?php

$tags =  $_GET["Tags"];

    foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name){
    $temp = $_FILES["files"]["tmp_name"][$key];
    $name = $_FILES["files"]["name"][$key];

    if(empty($temp))
    {
            break;
    }

Solution

  • The $_GET superglobal is populated by data from the query string of the URL.

    A form, with method="POST", will put data from the form controls in the request body, not the query string. (Data in the query string of the action will still be there).

    You need to read it from $_POST (except for files which are in $_FILES).