Reputation: 2480
I have done with download in pc device with below code
$file_url_source = "C:/test.xlsx";
$file_url = "C:/test.xlsx";
header('Content-Type: text/json; charset=UTF-8;');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';
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_url));
ob_clean();
flush();
readfile($file_url);
But it's not working for mobile device (I just tested it in Android mobile and it downloads the download.php
file). How can I make mobile devices download the file?
Upvotes: 0
Views: 2342
Reputation: 3814
This is all you need:
$file_url = "xxxxxx";
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($file_url) .'"');
readfile($file_url);
Your problem is with this line
header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';
# ^^^^^^^^^
# this is where your problem is, you never put the last " around the file name
Upvotes: 2