Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable safari from unzip downloaded file

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?

like image 761
Burbas Avatar asked Nov 24 '13 20:11

Burbas


People also ask

Why does Safari automatically unzip?

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.

How do I change download settings in Safari?

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.


2 Answers

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.

like image 44
SaschaM78 Avatar answered Oct 07 '22 00:10

SaschaM78


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.

like image 92
Jasper N. Brouwer Avatar answered Oct 06 '22 23:10

Jasper N. Brouwer