【发布时间】:2018-02-07 17:22:03
【问题描述】:
我使用这行代码在不同的浏览器中下载 pdf 文件。当我在桌面和安卓浏览器上尝试时,没问题,但是当我尝试 Ipad 和 iphone 设备时,下载不会发生。我不知道这段代码是否有错误..
$local_file = $path;
$download_file = $path;
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 100;
if(file_exists($local_file) && is_file($local_file))
{
/*header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: application/pdf');
header('Content-Length: '.filesize($local_file));
header('Content-Disposition: filename='.$download_file);
flush();
readfile($local_file);*/
header("Content-Type: application/octet-stream");
$file = $local_file;
header("Content-Disposition: attachment; filename=" . urlencode($file_name));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
}else {
die('Error: The file '.$local_file.' does not exist!');
}
【问题讨论】:
-
这段代码乱七八糟。