使用php curl上传文件

时间:2013-03-25 19:10:17

标签: php libcurl

发送错误的mime-type。文件类型为“video / mp4”,但“application / octet-stream”为发送方式。我想发送“video / mp4”。 卷曲选项($ file =真实路径)

$post = array('videoupload'=>'1','input_1'=>"@$file");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_INFILESIZE,(string)filesize($file));
curl_setopt($ch, CURLOPT_INFILE,fopen($file,'r'));

Http调试器输出

  
    

------------------------------ 94a50e65d9fe Content-Disposition:form-data;名称= “videoupload”

  
     

1   ------------------------------ 94a50e65d9fe Content-Disposition:form-data; NAME = “INPUT_1”; filename =“1.mp4”内容类型:   应用/八位字节流

我已经尝试过了

$post = array('videoupload'=>'1','input_1'=>"@$file;type=video/mp4");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_INFILESIZE,(string)filesize($file));
curl_setopt($ch, CURLOPT_INFILE,fopen($file,'r'));

curl_error out:

  

创建formpost数据失败

1 个答案:

答案 0 :(得分:0)

尝试在curl_setopt中添加CURLOPT_HTTPHEADER,就像那样

curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: video/mp4'));