您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现文件下载、支持中文文件名的示例代码

2024/5/2 14:34:21发布45次查看
1){ if(substr($filepath,0,1)=='/'){//判断是否为绝对路径 $filepath=$_server['document_root'].$filepath; } if(substr($filepath,-1)!=/){//检查最后是否为 / 结尾 $filepath=$filepath.'/'; } if(is_numeric(strpos($filepath,:\))){//检查是否为绝对路径 $filepath=str_replace(/,\,$filepath); } }elseif(strlen($filepath)==1&&$filepath!=/){ $filepath=$filepath./; }else{ $filepath=; } if(!file_exists($filepath.$filename)){ echo下载失败:所要下载的文件未找到;return; } /*------------- 发送下载相关的头部信息 -------------=*/ header(content-type: application/octet-stream); header(accept-ranges: bytes);//按照字节大小返回 header(accept-length: $filesize);//返回文件大小 header(content-disposition: attachment; filename=.$filename);//这里客户端的弹出对话框,对应的文件名 /*-------------
开始下载相关 -------------=*/ $filesize=filesize($filepath.$filename); $file=fopen($filepath.$filename,r);//打开文件 $filebuff=512; while($filesize>=0){ $filesize-=$filebuff; echo fread($file,$filebuff); } fclose($file); }?>
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product