通过发送http实现,假设$filesize代表文件大小,$filename代表文件名,文件内容为filecontent

header(“Content-type: application/octet-stream”);   //文件类型的mimetype
header(“Accept-Ranges: bytes”);          //如果不需要显示文件尺寸可省略
header(“Accept-Length: “.
$filesize);     //同上
header(“Content-Disposition: attachment; filename=” . $filename);
echo $filecontent;

这样就可以隐藏文件的实际路径,比如保存在数据库中的文件等。