我已经在pc设备中下载了以下代码
$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);
但它不适用于移动设备(我只是在Android手机上测试它并下载download.php
文件)。如何让移动设备下载文件?
答案 0 :(得分:2)
这就是你所需要的:
$file_url = "xxxxxx";
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($file_url) .'"');
readfile($file_url);
你的问题在于这一行
header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';
# ^^^^^^^^^
# this is where your problem is, you never put the last " around the file name