php 实现下载文件

来源:互联网 发布:淘宝网颜色分类 编辑:程序博客网 时间:2024/05/12 21:41
class DownLoadFile{public static function DownLoadFile1($filename){$file_name=iconv("utf-8", "gb2312", $filename);if (!file_exists($filename)){echo "文件不存在!";return;}$handle=fopen($filename, "r");$filesize=filesize($filename);header("Contect-type: application/octet-stream");header("Accept-Ranges: bytes");header("Accept-Length: $filesize");header("Content-Disposition: attachment; filename=$filename");$length = 1024;$filecount=0;while (!feof($handle) && ($filesize-$filecount)>0){$filedata=fread($handle, $length);$filecount+=$length;echo $filedata;}fclose($handle);}public static function DownLoadFile2($file){if ( file_exists ( $file )) {     header ( 'Content-Description: File Transfer' );     header ( 'Content-Type: application/octet-stream' );     header ( 'Content-Disposition: attachment; filename=' . basename ( $file ));     header ( 'Content-Transfer-Encoding: binary' );     header ( 'Expires: 0' );     header ( 'Cache-Control: must-revalidate' );     header ( 'Pragma: public' );     header ( 'Content-Length: '  .  filesize ( $file ));     ob_clean ();     flush ();     readfile ( $file );    exit;}}}

0 0
原创粉丝点击