Bobs-Bits.com - where stupidity meets reality

Fix hanging File Uploads in Safari

It seems there is a bug in Safari on Mac, that causes it to frequently fail to upload properly. This article on arfore.com suggests that it’s caused by a combination of HTTP Persistent Connections and multipart form data.

Several pages (including the one linked above, and this page on airbladesoftware.com suggest a JavaScript solution: as soon as the form submits, fire off an AJAX request.

My preferred solution is to send back a header telling Safari to close the connection, from the location the form is submitted to.

Usage

<?php header("connection: close"); ?>

For some reason it only works when the header is all lower case. "Connection: close" will not work.