獲取html頁面的內容下面是代碼:基本捲曲例如從遠程服務器
/*
* Example to fetch the example.com homepage into a file
*/
$curlObject = curl_init("http://AAA.BBB.CCC.DDD/");//AAA.BBB.CCC.DDD is the IP address of the remote server.
$file = fopen("example_homepage.txt", "w");
curl_setopt($curlObject, CURLOPT_FILE, $file);
curl_setopt($curlObject, CURLOPT_HEADER, 0);
curl_exec($curlObject);
curl_close($curlObject);
fclose($file);
它是基於例如here。我正在學習基本的cURL用法。預期的輸出是,在執行此PHP腳本後,應將位於安裝在我的遠程計算機(IP爲AAA.BBB.CCC.DDD
)中的XAMPP服務器的htdocs
目錄中的index.php
或index.html
的內容複製到example_homepage.txt文件中。
現在創建了example_homepage.txt
文件,但它是EMPTY。位於htdocs
安裝在遠程機器中的XAMPP服務器的目錄中的主頁(index.php
或index.html
)的內容不會複製到新創建的example_homepage.txt
中。
問題是爲什麼以及如何解決這個問題?