I can't believe I have to ask this, but for some reason my file isn't working. It's called ajax.php (though don't mind the name), and here is the exact code:
<?php
error_reporting(-1);
print_r($_POST);
print_r($_FILES);
?>
<form action="ajax.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="text" name="first" value="Bob" />
<input type="text" name="middle" value="James" />
<input type="text" name="last" value="Smith" />
<input type="file" name="something" />
<input type="submit" value="Submit" />
</form>
When I submit without attaching a file it prints data in the arrays. When I submit WITH a file no arrays populate.
What obvious thing am I missing???
Without file
Array ( [MAX_FILE_SIZE] => 30000 [first] => Bob [middle] => James [last] => Smith )
Array ( [something] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
With File
Array ( )
Array ( )
EXPECTED with File
Array ( [MAX_FILE_SIZE] => 30000 [first] => Bob [middle] => James [last] => Smith )
Array ( [something] => Array ( [name] => sample.jpg [type] => image/jpg [tmp_name] => whatever.jpg [error] => 0 [size] => 1248 ) )
UPDATE
It appears to be working on another server, it's DEFINITELY some configuration with my WAMP, meaning my question was incorrectly asked and therefore I'm closing it. Apologies to anyone who wasted time on my stupidity.
This appears to be a configuration problem. I'd say the post_max_size
is too small. This would explain why the $_POST
superglobal is empty when a file is uploaded. From the manual...
If the size of post data is greater than
post_max_size
, the$_POST
and$_FILES
superglobals are empty.
You need to set this value greater than upload_max_filesize
. For example, one of my servers has...
file_uploads=On
upload_max_filesize=12M
post_max_size=20M
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With