php7国内,php 7.1 国内下载地址PHP文件下载类

php 7.1 国内下载地址PHP文件下载类

更新时间: 2019-07-18 17:10:17   作者:第二电脑网   来源:第二电脑网   浏览数:404   我要评论

复制代码 代码如下:    //====================================================    电脑技术网认为此文章对《php 7.1 国内下载地址PHP文件下载类》说的很在理,www

复制代码 代码如下:

//====================================================

电脑技术网认为此文章对《php 7.1 国内下载地址PHP文件下载类》说的很在理,www.002pc.com为你提供最佳的学习电脑,php前端。

//   使用范例:

// $download=new download('php,exe,html',false);

//  if(!$download->downloadfile($filename))

//  {

//    echo $download->geterrormsg();

//  }

//====================================================

class download{

var $debug=true;

var $errormsg='';

var $Filter=array();

var $filename='';

var $mineType='text/plain';

var $xlq_filetype=array();

function download($fileFilter='',$isdebug=true)

{

$this->setFilter($fileFilter);

$this->setdebug($isdebug);

$this->setfiletype();

}

function setFilter($fileFilter)

{

if(empty($fileFilter)) return ;

$this->Filter=explode(',',strtolower($fileFilter));

}

function setdebug($debug)

{

$this->debug=$debug;

}

function setfilename($filename)

{

$this->filename=$filename;

}

function downloadfile($filename)

{

$this->setfilename($filename);

if($this->filecheck())

{

$fn = array_pop( explode( '/', strtr( $this->filename, '', '/' ) ) );

header( "Pragma: public" );

header( "Expires: 0" ); // set expiration time

header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" );

header( "Content-type:".$this->mineType );

header( "Content-Length: " . filesize( $this->filename ) );

header( "Content-Disposition: attachment; filename="$fn"" );

header( 'Content-Transfer-Encoding: binary' );

readfile( $this->filename );

return true;

}else

{

return false;

}

}

function geterrormsg()

{

return $this->errormsg;

}

function filecheck()

{

$filename=$this->filename;

if(file_exists($filename))

{

$filetype=strtolower(array_pop(explode('.',$filename)));

if(in_array($filetype,$this->Filter))

{

$this->errormsg.=$filename.'不允许下载!';

if($this->debug) exit($filename.'不允许下载!') ;

return false;

}else

{

if ( function_exists( "mime_content_type" ) )

{

$this->mineType = mime_content_type( $filename );

}

if(empty($this->mineType))

{

if( isset($this->xlq_filetype[$filetype]) )  $this->mineType = $this->xlq_filetype[$filetype];

}

if(!empty($this->mineType))

return true;

else

{

$this->errormsg.='获取'.$filename.'文件类型时候发生错误,或者不存在预定文件类型内';

if($this->debug) exit('获取文件类型出错');

return false;

}

}

}else

{

$this->errormsg.=$filename.'不存在!';

更多:php 7.1 国内下载地址PHP文件下载类

https://www.002pc.comhttps://www.002pc.com/phpbiancheng/2026.html

你可能感兴趣的PHP,下载,文件

No alive nodes found in your cluster

0踩

0 赞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值