Reputation: 61
if(file_exists($file_name)) {
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.basename($file_name));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_name));
ob_clean();
flush();
readfile($file_name);
exit;
}
I'm trying to force download files in php server. I've provided my code and it works well when browsed with desktop browsers. I face downloading issues when I try to download files with mobile browser. In mobile, chrome browser throws me an error saying 'server problem' while firefox browser downloads the file with .htm extension. Although my default mobile browser downloads the file successfully. How can I achieve the functionality successfully irrespective of the browsers ?
Upvotes: 1
Views: 94