<a href='{:get_page_action("dlfile", "","/base/sharefile")}?name={$name}&src={$src}'>下载</a>
点击下载。
function dlfile() { $name=input("name",''); $file_dir=input("src",''); if(empty($name) || empty($file_dir)){ echo "文件为空或者不能下载!"; $this->redirect('/base/sharefile/fileindex'); } $file_dir=$_SERVER['DOCUMENT_ROOT']."/upload/".$file_dir; $file_name = $name; $f = fopen( $file_dir , "rb+" ); $str = fread( $f , filesize( $file_dir ) ); // 读取输入流中的数据 fclose( $f ); // 关闭文件 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: ".filesize($file_dir)); Header("Content-Disposition: attachment; filename=".$name); ob_clean(); flush(); echo $str; }