2014-09-20 51 views
0

从远程服务器获取文件`我都存储在STRATO hidrive这我能够直接访问使用WebDAV和验证,像这样一个文件:使用httpful PHP库

https://username:[email protected]/path/to/my/file.zip

当我粘贴在我的地址栏中我可以直接下载文件。但我写它接受文件名作为URL参数的小文件吸气脚本,它会生成下载:

http://domain.com/getfile.php?filename=file.zip

这应该弹出一个下载对话框中同样的方式将直接链接

我想用httpful PHP库下载文件(如果可能不卷曲)

回答

0

结束了很简单:

$response = Request::getQuick($url); 

$path = parse_url($url, PHP_URL_PATH); 
$filename = substr($path, strrpos($path, '/') + 1); 
header('Content-Type: ' . $response->content_type); 
header('Content-Disposition: attachment; filename="' . $filename . '";'); 
header('Content-Length: ' . $response->headers['content-length']); 
readfile($url);