force download Safari and Chrome

Hi everyone !

First of all thanks for all the help in advance !

I’m trying to force the download of png files for a websites.
It works perfectly with Firefox but not with Safari (nothing happening when clicking) and Chrome (file corrupted).
I looked everywhere on internet for a fix but didn’t find any working solutions !
Please find below my code :

[php]
ob_end_clean();
//header(“Content-Type: application/force-download”);
header(“Content-Type: application/octet-stream”);
//header(“Content-Type: application/download”);
header(“Content-Transfer-Encoding: Binary”);
header(‘Accept-Ranges: bytes’);
header (“Content-Disposition: attachment; filename=”.basename($_REQUEST[‘path’]).";");
header(“Content-Description: File Transfer”);
header(‘Expires: 0’);
header(‘Pragma: public’);
header("Content-Length: ".$filesize($_REQUEST[‘path’]));
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Connection: close”);
readfile($_REQUEST[‘path’]);
}[/php]

Best,

Sponsor our Newsletter | Privacy Policy | Terms of Service