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;
}
}
}
php 实现下载文件
最新推荐文章于 2024-08-15 21:16:30 发布