I'm having a small problem with encrypted zip downloads in Safari. I've set all appropriate headers to force a download, but when the file's downloaded Safari tries to unzip it which results in a corrupt file. What I've read it's because Safari flags the file as safe and then tries to open it.
Is there a way to disable Safari from open the file after downloaded it?
This is a feature in Safari (for Macs only) that's easily disabled by going into your Safari preferences and unchecking the Open "Safe" files box. Click on Safari in the menu and then Preferences. Uncheck the checkbox.
Tip: To change where downloaded items are saved on your Mac, choose Safari > Settings, click General, then click the File download location pop-up menu and choose a location.
Definitely not the most elegant version there is but you may end up using a browser junction and have your download script change attachment name in combination with a notice for Safari users:
<?php
// $attachmentId used later-on would be a passed parameter that is used
// to define attachment name
$attachmentId= $_GET['id'];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($userAgent , 'Chrome') === FALSE &&
strpos($userAgent , 'Safari') !== FALSE)
{
$attachmentName= 'download.zipname';
$userNotice= 'SAFARI users: please rename the file from download.zipname to download.zip (due to Safari\'s ZIP file policy (more info))';
} else {
$attachmentName= 'download.zip';
$userNotice= '';
}
?>
<span class="notice"><?php print $userNotice; ?></span>
<a href="download.php?id=<?php print $attachmentId;?>" name="<?php print $attachmentName; ?>">Download</a>
So basically before starting the download, you would set up this pre-download page to define the required attachment name and to inform safari users about what has to be done to successfully download the file.
You can't disable this server-side :(
It's Safari's default behavior to unpack archives after downloading them. This can be disabled in Safari: Preferences
-> General
-> Uncheck the box Open "safe" files after downloading
at the bottom. But it's up to users themselves to do this.
If you like, you can display a warning about this behavior on the download page.
PS: The zip won't disappear! Safari may (optionally) unpack it, but the downloaded zip will still be next to the unpacked folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With