0

I am trying to upload some files on server with PHP and HTML.

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
    <body>
        <form action="upload3.php" method="post" enctype="multipart/form-data">
            <p><input type="file" name="upload[]"/><br></p>
            <p><input type="file" name="upload[]"/><br></p>
            <p><input type="file" name="upload[]"/><br></p>
            <input type='submit' name ='submit' value='Upload' />
        </form>
    </body>
</html>

PHP:

if(!empty($_FILES['submit']['name'][0])) {
    $name_arr = $_Files['upload']['name'];
    $tmp_arr = $_Files['upload']['tmp_name'];
    $type_arr = $_Files['upload']['type'];
    $error_arr = $_Files['upload']['error'];
    echo count($tmp_arr);
    for($i = 0; $i < count($tmp_arr); $i++) {
        if(move_uploaded_file($tmp_arr[$i], "test_uploads/" . $name_arr[$i])) {
            echo "Done";
        } else {
            echo "Nope";
        }
    }
} else
    echo "What's going on?";

And I always get the "What's going on?" message or "the size of" e.g. $tmp_arr "is 0".

GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
Janek
  • 3
  • 1
  • Still doesn't work. I have changed `($_Files['upload']['name'])`to `($_Files['submit']['name'])` but it isn't a clue. – Janek Dec 11 '17 at 20:51
  • 1
    there is no `['submit']['name']` run `print_r($_FILES)` to see the actual structure –  Dec 11 '17 at 20:52

1 Answers1

0

Use a var_dump($_FILES) to find out if the files are correctly uploaded. If it was, Then you will see the array structure for all info.

This should be avoided: $_Files, always a good practice to use correct case ($_FILES).