虽然这个技术已经很老了,不过对于我们这些PHP新手来说,还是值得学习下的。特别是重要的文件下载时,如果地址暴露出去,有可能别人能猜测你的结构从而下载你其它文件搞破坏啥的。这个我就不多说了。上代码吧!
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
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));
ob_clean();
flush();
readfile($file);
exit;
}
$file="file.zip";
可以这么定义,需要在同一级目录下面!本文链接:https://it72.com/8355.htm