Safari has a tendency to hang when uploading files, and it turns out there’s an easy fix. Looking around for a solution, I found this post outlining a way to fix it that the author found on the Basecamp. It’s just a couple of lines of code, and here they are in Mootools syntax:
1 2 3 4 5 | $$('input[type=submit]').addEvent('click',function(e) { if (Browser.Engine.webkit) { new Request({url: "/ping/close.php", asynch:false }).send(); } } |
This version will fire for every WebKit browser, which now also includes Chrome, so choose whatever sniffing method you like, but this will make a call to a PHP script returning a “Connection: close” header just before sending the upload.
Here’s that simple PHP:
1 | header("Connection: close"); |
Safari upload problem solved.