您的位置:首页 > 编程语言 > PHP开发

PHP之HEADER隐藏文件下载路径

2017-01-24 14:50 417 查看
说明:主要是利用readfile函数将文件另存下载
<?
$file="material_upload/Adobe Dreamweaver CS5.zip";  //$file里面必须是真实的下载路径
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;
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息