分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

PHP 大文件下载(方式1 不支持断点续传)

发布时间:2023-09-06 01:40责任编辑:胡小海关键词:PHP
public function download(){ ???$id = input(‘id‘); ???$item = Db::name(‘imgsubmit‘)->where([‘id‘=>$id])->find(); ???Db::name(‘imgsubmit‘)->where([‘id‘=>$id])->update([‘status‘=>1]); ???$tt = ltrim($item[‘zip‘],‘uploads/‘); ???$path = config(‘upload_path‘).DS.$tt; ???$arr = explode(‘/‘,$path); ???$iname=$item[‘username‘].‘_‘.$item[‘order_no‘]; ???/*$filename = $arr[count($arr)-1];*/ ???$filename=$iname.‘.zip‘; ???//$file ?= ?fopen($path, "rb"); ???????if (file_exists($path)) { ????????$filesize=filesize($path); ????????header(‘Content-Description:File Transfer‘); ????????header("Content-Type:application/octet-stream"); ????????header(‘Content-Transfer-Encoding:binary‘); ????????header("Accept-Ranges: bytes"); ????????header(‘Expires:0‘); ????????header(‘Cache-Control:must-revalidate‘); ????????header(‘Pragma:public‘); ????????header("Content-Length:".$filesize); ????????header("Content-Disposition:attachment;filename=".$filename); ???????//以下内容是引用网友的代码,由于原来的出处找不到了,在此表示万分感谢和抱歉。 ???????//打开文件 ????????$fp = fopen($path, "rb"); ????????//设置指针位置 ????????ob_start(); ???????fseek($fp,0); ????????//虚幻输出 ????????while (!feof($fp)) { ????????????//设置文件最长执行时间 ????????????set_time_limit(0); ????????????print (fread($fp, 1024 * 8)); //输出文件 ????????????flush(); //输出缓冲 ????????????ob_flush(); ????????} ????????fclose($fp); ????????exit ();}else{echo "文件不存在!!!";die();}}

PHP 大文件下载(方式1 不支持断点续传)

原文地址:http://blog.51cto.com/13562606/2066555

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved