PHP HTML: file loading does not work

I cannot believe that I should ask about this, but for some reason my file does not work. It is called ajax.php (although not against 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 send without attaching a file, it prints the data in arrays. When I send WITH with a file, no arrays are populated.

What obvious thing am I missing ???

No 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 A 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 seems that it is working on another server, DEFINING some configuration with my WAMP, that is, my question was asked incorrectly, and therefore I close it. I apologize to those who spent time on my stupidity.

+4
source share
3 answers

. , post_max_size . , $_POST , . ...

- , post_max_size, $_POST $_FILES .

, upload_max_filesize. , ...

file_uploads=On
upload_max_filesize=12M
post_max_size=20M
+2

Ajax, . javascript-. ?

2 . , , -, ajax .

0

MAX_FILE_SIZE

 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

The hidden field MAX_FILE_SIZE is measured in bytes, so either replace it with some higher value, or delete it.

Try this with

      <form action="ajax.php" method="post" enctype="multipart/form-data">
       <input type="hidden" name="MAX_FILE_SIZE" value="2597152" />
       <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>

CONCLUSION:

  Array
   (
          [MAX_FILE_SIZE] => 2597152
          [first] => Bob
          [middle] => James
          [last] => Smith
   )
 Array
 (
    [something] => Array
      (
           [name] => Desert.jpg
           [type] => image/jpeg
           [tmp_name] => D:\wamp\tmp\php3191.tmp
           [error] => 0
           [size] => 845941
     )

  )

I suggest you delete MAX_FILE_SIZE, because it is not a good practice to interest the user to enter. it is better if you use the SERVER side check for this.

0
source

All Articles