phpformspostfile-uploadenctype

Posting file with form just makes PHP script hang when enctype set


My form with the method of POST for uploading a file only makes the receiving script hang (or it doesn't load properly), when enctype is set to multipart/form-data. In Safari it takes a couple of minutes before the script collapses (gives up), but in Chrome it goes down right away. By down I mean that the user ist taken to the root of the site (/).

No errors to be found in the error log.

I've managed to make the form function without enctype and/or a file input, but then naturally, no file is posted.

It is a WAMP server with PHP7. Ini settings have all been carefully checked to be big enough.

The scripts worked until a couple of weeks ago, but the IT department cannot point to any specific updates that might be the cause.

<form name="fileupload" action="fileReceive.php" enctype="multipart/form-data" method="POST">
    <input type="text" name="ahiddenvalue" value="The hidden value">
    <input type="file" name="upfile" id="fileToUpload" accept=".pdf, application/pdf">
    <input type="submit" name="Upload" value="Upload file">
</form>

File receiving script, fileReceive.php:

exit("<pre>".print_r($_REQUEST)."\n".print_r($_FILES)."</pre>");

The loading bar in the address field of the browser just gets started, and hangs in Safari till about two minutes. No message about max-execution_time in the error log.


Solution

  • I found the reason: An url rewrite was set up un Apache with only lowercase file suffixes. When trying to fetch a file with uppercase file suffix, the script that was 'url rewritten' to, did not catch the file and just stopped everything by displaying the top page of the site.