-1

私が試したこと/試していること

function download_data($target_document,$outfile_location) 
{
    log_message('info', 'Downloading every page in data set');

    do 
    {   

       $ch = curl_init ($target_document.'apiKey=' . self::$API_KEY);       
       $fp = fopen($outfile_location . "data.zip", "w");

        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_exec($ch);
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        fclose($fp);

        $this->http_status = $http_status;

            if($this->http_status != 200) 
            {
                $this->data_retry_count += 1;   
            }

    } while($this->http_status != 200 && $this->data_retry_count < $this->retry_max);

        if($this->http_status == 200) 
        {

            return;

        }

}

上記のコードを使用すると、内容のない圧縮(zip)を取得する以外は、すべてがスムーズに進みます。ブラウザにターゲットドキュメントをダウンロードすると、機能します。zipファイルの内容を取得するためにcurlで何か別のことをする必要がありますか?

$thisこの関数はクラスの一部であり、これらの変数はクラス内に含まれる変数を表すため、変数は無視してください。

4

2 に答える 2

1

これで問題が解決するはずです。

これにより、ZIPが空になることなくダウンロードされます。これは、少し前の問題の修正でした。

echo curl_error($ch);また、デバッグを検討する必要があります。

<?php 
function get_file1($file, $local_path, $newfilename) { 
    $err_msg = ''; 
    echo "<br>Attempting message download for $file<br>"; 
    $out = fopen($newfilename, 'wb'); 
    if ($out == FALSE){ 
      print "File not opened<br>"; 
      exit; 
    } 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_FILE, $out); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_URL, $file); 

    curl_exec($ch); 
    echo "<br>Error is : ".curl_error ( $ch); 

    curl_close($ch); 
    //fclose($handle); 

}
?>

ソース: http://www.weberdev.com/get_example.php3?ExampleID=4009

于 2012-07-04T03:05:20.360 に答える
-1

あなたがcurlでFTPまたはwgetタイプの関数を実行しようとしているように聞こえます。カールでどれだけうまく機能するかわかりません。代替案:

PHPのftpの場合:

http://php.net/manual/en/book.ftp.php

PHPのwgetのような機能については、試してみることができます

file_get_contents($ url)

http://php.net/manual/en/function.file-get-contents.php

于 2012-07-04T02:50:21.397 に答える