php下载远程大文件(获取远程文件大小)
2017-06-16 16:47
746 查看
function download_file($url) { // $url = http://192.168.8.95/vm/download_file?downurl=http://192.168.8.96/download/test1.tar.gz; // 要下载的文件可能在本地,也可能在其他节点服务器 if (empty($url) || false === @fopen($url, 'rb')) { exit('文件不存在'); } // 处理中文名 $filename = basename($url); $user_agent = $_SERVER["HTTP_USER_AGENT"]; if (false !== stripos($user_agent, 'Trident')) { $filename = rawurlencode($filename); } // 文件目标 list($host, $dl_file) = explode('download', $url); $server_addr = $_SERVER['SERVER_ADDR']; if (false !== stripos($host, $server_addr)) { // 本地文件 header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('X-Accel-Redirect: /download' . $dl_file); exit; } else { // 文件在其他节点服务器 $header = get_headers($url, 1); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . $header['Content-Length']); readfile($url); exit; } }
相关文章推荐
- php下载远程大文件(获取远程文件大小)的实例
- php获取远程文件大小
- PHP获取远程文件大小 如果加判断文件大小以KB MB GB
- PHP 获取远程文件的大小的3种方法
- php获取远程文件大小
- php获取远程文件大小
- php获取远程文件内容与大小的函数代码
- php获取远程文件大小
- php获取远程文件大小
- php获取远程文件大小
- php获取远程文件的内容和大小
- php获取远程文件的内容和大小
- PHP 获取远程文件大小常用方法总结
- php获取远程文件大小的三种方法(实例代码)
- PHP 获取远程文件的大小
- 用vc下载和获取远程文件大小
- PHP下载远程文件及获取文件内容
- PHP 获取远程文件大小的3种解决方法
- PHP 获取远程文件大小的3种解决方法
- 获取远程下载文件的大小