Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP中的Bings广告下载活动绩效报告_Php_Download_Fopen_Ads_Bing Api - Fatal编程技术网

使用PHP中的Bings广告下载活动绩效报告

使用PHP中的Bings广告下载活动绩效报告,php,download,fopen,ads,bing-api,Php,Download,Fopen,Ads,Bing Api,一个星期以来我就被这件事深深打动了。请告诉我是否有人能帮我解决这个问题 我试过他们给我的。我尝试只下载活动绩效报告,在这里我可以下载一个包含csv文件的zip文件。是另一个直接的例子,我遵循的关键字,并做了同样的方式为竞选活动的表现。这给了我一个下载报告的链接。当我试图手动下载url时,我可以下载,但无法通过代码下载 function DownloadFile($reportDownloadUrl, $downloadPath) { if (!$reader = fopen($repor

一个星期以来我就被这件事深深打动了。请告诉我是否有人能帮我解决这个问题

我试过他们给我的。我尝试只下载活动绩效报告,在这里我可以下载一个包含csv文件的zip文件。是另一个直接的例子,我遵循的关键字,并做了同样的方式为竞选活动的表现。这给了我一个下载报告的链接。当我试图手动下载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);
}

但我无法下载该文件。我无法从那里继续前进,因此非常感谢任何帮助,如以任何其他形式下载报告或当前方法中的简单代码更改。提前谢谢

当我尝试此功能时,下载文件功能也出现问题,因此将其替换为其他版本

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;
}

您是在服务器上还是在桌面上运行此操作?服务器上运行的$DownloadPath变量是什么。