html - Php 7 form doesn't work with enctype="multipart/form-data" and method="post"

544

I am using PHP 7.0.9 with IIS 8. I have a html form to upload an image. The method isPOST, the action is correct, and enctype is "multipart/form-data". However, when I submit the form, the page hangs, as if it was trying to upload the selected file endlessly - it weight about 30kb, not a big deal...

Here is my form :

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="text" name="textInput" id="textInput">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

And here is upload.php :

<?php

echo "ok<br/>";
var_dump($_POST);

?>

As is, when I click on "Upload Image", the page hangs as if it was uploading the file endlessly.

But if I remove theenctype or if I change the action byget, the form is submited and prints :

ok
array(0) { }

The$_POST array is obviously empty, but why doesn't it works withenctype="multipart/form-data" ?

FYI:

file_uploads = On
upload_max_filesize = 20M
max_file_uploads = 20
upload_tmp_dir = C:\Windows\temp

...and C:\Windows\temp is writeable for Everyone. Yes, the group Everyone - I am really annoyed by this, and I don't want any rights problem.

Some tests later...

If I use :

<form action="upload.php" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="text" name="textInput" id="textInput">
    <input type="submit" value="Upload Image" name="submit">
</form>

The result is :

ok
array(3) { ["fileToUpload"]=> string(13) "imageName.png" ["textInput"]=> string(4) "blah" ["submit"]=> string(12) "Upload Image" }

It seems to be a problem between the method and the enctype.

EDIT

For what it worth, I think it's definitly a IIS problem: when I look in the IIS log I see the request for the form :

2017-01-16 13:28:19 X.X.X.X GET /testupload.html - 80 - X.X.X.X Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 - 304 0 0 1140

But nothing is written when I submit the form; so I don't even know if IIS is receiving the request.

627

Answer

Solution:

Finally, the culprit was Glimpse. I absolutely don't know why, but once I had removed every traces of the plugin in the web.config, upload via PHP worked again.

48

Answer

Solution:

"I cannot replicate it with the same php version, but with Apache instead of IIS"

Take a look on your IIS firewall.

618

Answer

Solution:

use $_FILES (for files) instead of $_POST

People are also looking for solutions to the problem: php - what are the settings required while maintainig logs in laravel ? and at which time I should use which severity level to maintain logs?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.