1

ファイルのサイズを読み取る必要がありますが、サーバーから最初にファイルをダウンロードするように強制されています。応答ヘッダーの 1 つが Content-Type: application/force-download であり、curl 入力をバイパスしているように見えることに注意してください...

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
curl_exec($ch);
$bytes = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);

何か案は?

4

2 に答える 2

1
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

これらの 2 行はリセットされCURLOPT_NOBODYます。

CURLOPT_NOBODYmethod を HEAD にCURLOPT_POST変更し、POST に変更します。

ソース: http://php.net/manual/en/function.curl-setopt.php

于 2012-07-03T13:08:26.407 に答える
0

Curl は force-download ヘッダーに準拠していますが、file_get_contents を使用して、ファイル ダウンロードのダウンロードを 1 バイトのみに制限できます。これで問題は解決しました!

$postdata = http_build_query(
    array(
        'username' => "",
        'password' => ""
    )
);
$params = array(
    'http' => array
    (
      'method' => 'POST',
      'header'=>"Content-type: application/x-www-form-urlencoded\r\n",
      'content' => $postdata
    )
);
$ctx = stream_context_create($params);
file_get_contents($url,false,$ctx,0,1);
$size = str_replace("Content-Length: ","",$http_response_header[4]);
于 2012-07-03T13:16:32.977 に答える