我正在尝试从我的localhost下载一个zip文件。该文件正在下载,但在我打开它时会显示错误消息“无效”。 我使用以下代码: -
$filename = "markers.zip";
`if(file_exists($filename) && is_readable($filename)){
header("Content-Disposition: attachment; filename=".basename($filename));
header("Content-Type: application/force-download");
header("Content-Type: application/zip");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($filename));
flush();
$fp = fopen($filename, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush();
}
fclose($fp);
exit;
}`
答案 0 :(得分:1)
<?php
$file = "file.zip";
header('Content-type: application/x-download');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.filesize($file));
readfile($file);
?>