製作下載按鈕,實現下載功能。
a鏈接如下:
<a href="download.php" target="_self" class="btn btn-success hide" id="btn-download-errorinfo">下载</a>
簡單下載自定義函數:
/** * download files * $file_path : the file to download * $out_filename: 下载显示的文件名称 */ function _download($file_path,$out_filename="download.log") { if(is_file($file_path)) { $file = fopen($file_path, "r"); // 打开文件 if($file) { //自定下載顯示義文件名 $out_filename = str_replace(pathinfo($out_filename,PATHINFO_EXTENSION),'',$out_filename)
.date("Y.m.d.His")
.'.'
.pathinfo($out_filename,PATHINFO_EXTENSION);
// 输入文件标签 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); header('Content-Transfer-Encoding: binary'); Header("Accept-Length: ".filesize($file_path)); //rename Header("Content-Disposition: attachment;filename=".$out_filename); // 输出文件内容 echo fread($file, filesize($file_path)); fclose($file); exit(); }else{ echo false; } }else{ echo false; } }
---- 始终相信这句:
----“做每天该做的事,不计结果!”
---- 因爲對於編程還只是新手,對很多知識掌握的不牢靠,歡迎大家批評指正~~|=-=|~~
----“做每天该做的事,不计结果!”
---- 因爲對於編程還只是新手,對很多知識掌握的不牢靠,歡迎大家批評指正~~|=-=|~~