PHP文件下载函数
/** * 下载本地文件 * @param array $file 文件信息数组 * @param callable $callback 下载回调函数,一般用于增加下载次数 * @param string $args 回调函数参数 * @return boolean 下载失败返回false */ private function downLocalFile($file, $callback = null, $args = null){ if(is_file($file["rootpath"].$file["savepath"].$file["savename"])){ /* 调用回调函数新增下载数 */ is_callable($callback) && call_user_func($callback, $args); /* 执行下载 */ //TODO: 大文件断点续传 header("Content-Description: File Transfer"); header("Content-type: " . $file["type"]); header("Content-Length:" . $file["size"]); if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) { //for IE header("Content-Disposition: attachment; filename="" . rawurlencode($file["name"]) . """); } else { header("Content-Disposition: attachment; filename="" . $file["name"] . """); } readfile($file["rootpath"].$file["savepath"].$file["savename"]); exit; } else { $this->error = "文件已被删除!"; return false; } }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: PHP处理后端&接口访问超时