1

`我有一个文件存储在 Strato hidrive 上,我可以使用 webdav 和身份验证直接访问它,如下所示:

https://username:password@webdav.hidrive.strato.com/path/to/my/file.zip

当我将其粘贴到地址栏中时,我可以直接下载该文件。但我正在编写一个小文件 getter 脚本,它接受文件名作为 URL 中的参数,它将生成下载:

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

这应该会弹出一个下载对话框,就像直接链接一样

如果可能,我想使用httpful php 库下载文件(不是 cURL)

4

1 回答 1

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);
于 2014-09-20T19:14:59.870 回答