php实现文件安全下载 程序如下: $file_name = “info_check.exe”; $file_dir = “/public/www/download/”; if (!file_exists($file_dir . $file_name)) { //检查文件是否存在 echo “文件找不到”; exit; } else { $file = fopen($file_dir . $file_name,”r”); //打开文件 //输入文件标签 header(“content-type: application/octet-stream”); header(“accept-ranges: bytes”); header(“accept-length: “.filesize($file_dir . $file_name)); header(“content-disposition: attachment; filename=” . $file_name); //输出文件内容 echo fread($file,filesize($file_dir . $file_name)); fclose($file); exit;} 而如果文件路径是”http”或者”ftp”网址的话,则源代码会有少许改变,程序如下: $file_name = “info_check.exe”; $file_dir = “www.easycn.net/”; $file = @ fopen($file_dir . $file_name,”r”); if (!$file) { echo “文件找不到”; } else { header(“content-type: application/octet-stream”); header(“content-disposition: attachment; filename=” . $file_name); while (!feof ($file)) { echo fread($file,50000); } fclose ($file); } 这样就可以用php直接输出文件了
http://www.bkjia.com/phpjc/532313.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/532313.htmltecharticlephp实现文件安全下载 程序如下: $file_name = info_check.exe; $file_dir = /public/www/download/; if (!file_exists($file_dir . $file_name)) { //检查文件是否存…