2014-09-20 56 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);