2014-06-11 3 views
0

api를 통해 파일을 업로드하는 데 다음 코드를 사용하고 있습니다. 하지만 업로드 한 후 파일 내용 유형이 잘못되었습니다 (단지 약 26 바이트). 콘텐츠 유형은 $ data_string의 길이가됩니다. 콘텐츠 길이를 업로드 파일의 파일 크기로 변경하려고했습니다. 하지만 그 후에는 API가 작동하지 않습니다. 어떤 코딩을 잘못 했습니까?PHP curl로 파일을 업로드 할 때 콘텐츠 길이 문제가 발생합니다.

$data  = array("Content" => "file.wav"); //around 4mb 
$data_string = json_encode($data); 
$ch   = curl_init(); 

curl_setopt($ch, CURLOPT_URL, 'URL'); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);       
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                   
    'Content-type: audio/wav',                   
    'Content-Length: ' . strlen($data_string))                  
);      
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
$data  = curl_exec($ch); 

curl_close($ch); 

답변

0

$ data_string 문자열의 한 쌍을 구비하고, 따라서 그것은 그 배열이 아닌 파일의 사이즈의 크기 것이다 배열을 코딩 JSON 의해 형성되는 문자열이다. 파일 크기를 찾으려고한다면 파일 크기() 함수를 사용하는 것이 좋습니다. 그것이 올바른 형태 인 경우 :

http://www.php.net//manual/en/function.filesize.php

* 또한 "$ 암호 $ 사용자 이름"을 확인하십시오.

관련 문제