一段php的文件下载函数(可下任意文件类型)
2009-09-25 文章来源:互联网 浏览次数:1151
分享文章
- <?php
- if(isset($_GET["file"])){
- downFile(realpath($_GET["file"]));
- }
- else
- {
- echo("请输入文件路径!");
- }
- function downFile($sFilePath)
- {
- if(file_exists($sFilePath)){
- $aFilePath=explode("/",str_replace("\\","/",$sFilePath),$sFilePath);
- $sFileName=$aFilePath[count($aFilePath)-1];
- $nFileSize=filesize ($sFilePath);
- header ("Content-Disposition: attachment; filename=" . $sFileName);
- header ("Content-Length: " . $nFileSize);
- header ("Content-type: application/octet-stream");
- readfile($sFilePath);
- }
- else
- {
- echo("文件不存在!");
- }
- }
- ?>

文章评论(查看全部)