2014-06-24 57 views
0

自從一個星期以來,我感到非常震驚。請告訴我,如果有人能幫我解決這個問題。使用PHP中的Bings廣告下載廣告系列效果報告

我試過this samples他們給出。我只想下載廣告系列的效果報告,我可以下載其中包含csv文件的zip文件。 Here是我遵循關鍵字的另一個直接示例,並且對廣告系列的效果也採用了相同的方式。哪個給我一個鏈接來下載報告。當我試圖手動下載URL時,我可以下載,但無法通過我的代碼下載。

function DownloadFile($reportDownloadUrl, $downloadPath) { 
    if (!$reader = fopen($reportDownloadUrl, 'rb')) { 
     throw new Exception("Failed to open URL " . $reportDownloadUrl . "."); 
    } 
    if (!$writer = fopen($downloadPath, 'wb')){ 
     fclose($reader); 
     throw new Exception("Failed to create ZIP file " . $downloadPath . "."); 
    } 
    $bufferSize = 100 * 1024; 
    while (!feof($reader)) { 
     if (false === ($buffer = fread($reader, $bufferSize))) { 
      fclose($reader); 
      fclose($writer); 
      throw new Exception("Read operation from URL failed."); 
     } 

     if (fwrite($writer, $buffer) === false) { 
      fclose($reader); 
      fclose($writer); 
      $exception = new Exception("Write operation to ZIP file failed."); 
     } 
    } 
    fclose($reader); 
    fflush($writer); 
    fclose($writer); 
} 

但我無法下載該文件。我無法從那裏繼續前進,所以任何幫助如下載任何其他形式的報告或簡單的代碼更改在當前的方法非常感謝。提前致謝。

+0

你的服務器或桌面上運行該更換呢?什麼是$ DownloadPath變量?運行在服務器上的 – noelnoegdip

+0

。 – Sreenath

回答

0

當我嘗試這樣做我也有與DownloadFile功能問題,從而爲不同的版本

function DownloadFile($reportDownloadUrl, $downloadPath) { 
    $url = $reportDownloadUrl; 
    // Example for the path would be in this format 
    // $path = '/xxx/yyy/reports/keywordperf.zip'; 
    // using the server path and not relative to the file 
    $path = $downloadPath; 

    $fp  = fopen($path, 'w'); 
    $ch  = curl_init($url); 

    curl_setopt($ch, CURLOPT_SSLVERSION, 3); 
    curl_setopt($ch, CURLOPT_FILE, $fp); 

    if($result = curl_exec($ch)) { 
     $status = true; 
    } 
    else 
    { 
     $status = false; 
    } 

    curl_close($ch); 
    fclose($fp); 

    return status; 
} 
相關問題