国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php利用header函數(shù)下載各種文件

2024-05-04 23:49:19
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了php header函數(shù)下載文件實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

http://www.php.net/manual/en/function.readfile.php

<?php/*** 下載文件* header函數(shù)**/dl_file($_GET ['filename']);function dl_file($file){ $file = ".//images//" . $file; //First, see if the file exists  if (! is_file ( $file )) {  die ( "<b>404 File not found!</b>" ); }  // Gather relevent info about file $len = filesize ( $file ); $filename = basename ( $file ); $file_extension = strtolower ( substr ( strrchr ( $filename, "." ), 1 ) );  // This will set the Content-Type to the appropriate setting for the file switch ($file_extension) {  case "pdf" :   $ctype = "application/pdf";   break;  case "exe" :   $ctype = "application/octet-stream";   break;  case "zip" :   $ctype = "application/zip";   break;  case "doc" :   $ctype = "application/msword";   break;  case "xls" :   $ctype = "application/vnd.ms-excel";   break;  case "ppt" :   $ctype = "application/vnd.ms-powerpoint";   break;  case "gif" :   $ctype = "image/gif";   break;  case "png" :   $ctype = "image/png";   break;  case "jpeg" :  case "jpg" :   $ctype = "image/jpg";   break;  case "mp3" :   $ctype = "audio/mpeg";   break;  case "wav" :   $ctype = "audio/x-wav";   break;  case "mpeg" :  case "mpg" :  case "mpe" :   $ctype = "video/mpeg";   break;  case "mov" :   $ctype = "video/quicktime";   break;  case "avi" :   $ctype = "video/x-msvideo";   break;    // The following are for extensions that shouldn't be downloaded  // (sensitive stuff, like php files)  case "php" :  case "htm" :  case "html" :  case "txt" :   die ( "<b>Cannot be used for " . $file_extension . " files!</b>" );   break;    default :   $ctype = "application/force-download"; }   $file_temp = fopen ( $file, "r" );   // Begin writing headers header ( "Pragma: public" ); header ( "Expires: 0" ); header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header ( "Cache-Control: public" ); header ( "Content-Description: File Transfer" ); // Use the switch-generated Content-Type header ( "Content-Type: $ctype" ); // Force the download $header = "Content-Disposition: attachment; filename=" . $filename . ";"; header ( $header ); header ( "Content-Transfer-Encoding: binary" ); header ( "Content-Length: " . $len );   //@readfile ( $file ); echo fread ( $file_temp, filesize ( $file ) ); fclose ( $file_temp );  exit ();}?>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 手游| 武强县| 湘西| 宁阳县| 临清市| 宜宾市| 弥勒县| 保山市| 丹凤县| 沭阳县| 林口县| 建始县| 桃园县| 三江| 裕民县| 阜宁县| 成安县| 灯塔市| 巍山| 呼伦贝尔市| 香港| 张家口市| 胶州市| 阜南县| 新乡县| 陆川县| 贵南县| 镇赉县| 聂拉木县| 小金县| 洪洞县| 双柏县| 成安县| 襄垣县| 班戈县| 怀安县| 项城市| 万载县| 房产| 永寿县| 岳池县|