我用這個函數成功下載了SWF文件(flash遊戲)。當我爲一個特定的站點使用這個腳本時,它會下載所有的遊戲(我告訴腳本從列表中下載4個遊戲),確切大小爲299bytes?我試着用Google Chrome下載這些遊戲,並且下載成功了。在我使用的CURL函數中是否存在缺失或者下載算法不夠好?任何幫助將不勝感激。使用PHP和cURL下載文件
function saveFlash($fullPaths,$folder,$gamenames,$i){
$curl = curl_init($fullPaths[$i]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//Create a new file in the given folder
$fp = fopen($folder."/".$gamenames[$i].".swf", 'w');
if ($fp == FALSE){
echo "File not opened<br>";}
//Ask cURL to write the contents to a file
curl_setopt($curl, CURLOPT_FILE, $fp);
//Execute the cURL session
curl_exec ($curl);
//Close cURL session and file
curl_close ($curl);
fclose($fp);
}
文本編輯提供了以下
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://www.freeonlinegames.com/">here</a>.</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at freeonlinegames.com Port 80</address>
</body></html>
你用文本編輯器看過那些299字節的文件嗎?很可能它會是「對不起,不允許直接訪問」的某種錯誤消息。 – 2011-06-14 16:12:49
您的腳本被阻止。查看返回的數據(應該是HTML)是有原因的。 – hakre 2011-06-14 16:13:09
它說,該文件已移動 – George 2011-06-14 16:14:34