-2

I have the following code
index.html

<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="test" id="test" class="input"><br>
<input type="submit" value="Go!" class="input btn">
</form>

upload.php

<?php
$x = $_FILES["test"]["name"];
echo $x;
?>

And it returns this

Notice: Undefined index: test in C:\xampp\htdocs\example\upload\upload.php on line 2

I have no idea what's happening here, it all look right to me?

I've seen PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" but that hasn't helped me

shadowsheep
  • 14,048
  • 3
  • 67
  • 77
Jon
  • 9
  • 2
  • 1
    it complains about an index 'testin', which is not present in your posted code. – Dormilich Feb 27 '18 at 17:49
  • My bad, edited. Just a typo – Jon Feb 27 '18 at 17:51
  • FYI, you should always copy/paste code, errors, etc exactly as-is instead of transcribing them by hand. – Patrick Q Feb 27 '18 at 17:52
  • 2
    To troubleshoot, you might try outputting the `$_FILES` array. Something like `echo "
    ".print_r($_FILES,true)."
    ";`
    – showdev Feb 27 '18 at 18:08
  • *"I've seen PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" but that hasn't helped me"* - Well, I for one do not see where you used `isset()` and/or `!empty()`. – Funk Forty Niner Feb 27 '18 at 18:21
  • 1
    btw; you can't just do this `$x = $_FILES["test"]["name"];` - since there needs to be a tmp name first. PHP doesn't know what name it is yet, since it was never uploaded in the first place. – Funk Forty Niner Feb 27 '18 at 18:22
  • that possible and most likely duplicate contains a wiki answer I posted in there https://stackoverflow.com/a/46620059/1415724 and it contains everything you need to do this. You try that, @Funk (Niner) me when you have and/or edited your question. You were also given an answer but didn't comment or accept it if that is what the problem was. If not, then don't be surprised if you see your question gets hammered (closed). – Funk Forty Niner Feb 27 '18 at 18:23

1 Answers1

0

You should verify you php.ini file, when the allowed size is exceeded by the file you are trying to upload, so, the servers complain and doesn't fill the $_FILES variable.