栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用PHP和Mysql DB下载文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用PHP和Mysql DB下载文件

SomePage.php

<a href="download.php?FileNo=<?echo $FileNo;?>">File Name</a>

download.php

$FileNo=$_GET['FileNO'];//Use Mysql Query to find the 'full path' of file using $FileNo.// I Assume $FilePaths as 'Full File Path'.download_file($FilePaths);function download_file( $fullPath ){  if( headers_sent() )    die('Headers Sent');  if(ini_get('zlib.output_compression'))    ini_set('zlib.output_compression', 'Off');  if( file_exists($fullPath) )  {    $fsize = filesize($fullPath);    $path_parts = pathinfo($fullPath);    $ext = strtolower($path_parts["extension"]);    switch ($ext)     {      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;      default: $ctype="application/force-download";    }    header("Pragma: public");     header("Expires: 0");    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    header("Cache-Control: private",false);     header("Content-Type: $ctype");    header("Content-Disposition: attachment; filename="".basename($fullPath)."";" );    header("Content-Transfer-Encoding: binary");    header("Content-Length: ".$fsize);    ob_clean();    flush();    readfile( $fullPath );  }   else    die('File Not Found');}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/416699.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号