“我有一个存储在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
这应该会弹出一个下载对话框,就像直接链接一样。
如果可能的话,我想使用希帕托 php库下载文件(而不是cURL)。
发布于 2014-09-20 19:14:59
结果是很简单的:
$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);https://stackoverflow.com/questions/25952127
复制相似问题