2012-07-03 2 views
1

파일의 크기를 읽어야하지만 서버가 먼저 다운로드해야합니다. ...콘텐츠 유형을 무시하십시오 : CURL의 application/force-download

$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); 

모든 아이디어 응용 프로그램/강제로 다운로드하고 내 컬 입력을 무시하는 것 같다 내가 응답 헤더 중 하나주의 은 콘텐츠 형식을 무엇입니까?

+0

"Content-Type : application/force-download"는 말을 올릴 의미가 전혀 없으며 단순히 무시합니다. 헤더의 요점은 브라우저가 브라우저를 인식하지 못하게하기위한 것이므로 인라인으로 표시하려고하는 대신 대신 다운로드하는 것이 좋습니다. 이것은 현대의 브라우저가 대개 Content-Type을 무시하고 대신 데이터를 "스니핑 (sniffing)"하여 컨텐트를 결정할 것이라고 말했습니다 ...이 (구식) 인터넷 초안에서 설명 된 것처럼 http://tools.ietf.org/ html/draft-abarth-mime-sniff-06 –

답변

0

컬 힘 다운로드 헤더와 일치하지만 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]); 
1
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

이 두 행은 CURLOPT_NOBODY을 재설정합니다.

CURLOPT_NOBODY을 HEAD로 변경하고 CURLOPT_POST을 POST로 변경합니다.

자료 : http://php.net/manual/en/function.curl-setopt.php

+0

감사합니다. 이것이 작동하지 않는 이유를 설명하고 아래에 해결 방법을 게시했습니다. –

관련 문제