我試圖使用php和curl在htaccess保護的目錄中下載文件。這是我的代碼:使用PHP和CURL下載htaccess保護的文件
$username = "MyUsername";
$password = "MyPassword";
$url = "http://www.example.com/private/file.pdf";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
但是這段代碼什麼都不做......我該如何啓動file.pdf的下載?
謝謝!
另外,如果我回聲$輸出,我得到這個:
Array ([url] => http://www.example.com/private/file.pdf [content_type] => application/pdf [http_code] => 200 [header_size] => 264 [request_size] => 116 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.007898 [namelookup_time] => 0.006777 [connect_time] => 0.006858 [pretransfer_time] => 0.006922 [size_upload] => 0 [size_download] => 27369 [speed_download] => 3465307 [speed_upload] => 0 [download_content_length] => 27369 [upload_content_length] => 0 [starttransfer_time] => 0.007839 [redirect_time] => 0)
你的意思是「什麼也不做」?什麼是輸出以及`$ info`中返回的錯誤是什麼? – 2011-02-09 11:48:10
它不會返回任何錯誤,在$ info返回200確定,但下載不會啓動... – nmarti 2011-02-09 12:25:42