使用php curl上传文件

发送错误的mime类型 . 文件类型为“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; name =“videoupload”1 ------------------------------ 94a50e65d9fe Content-Disposition:form-data; NAME = “INPUT_1”; filename =“1.mp4”Content-Type:application / octet-stream

我试过了

$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出来:

创建formpost数据失败

回答(1)

3 years ago

尝试在curl_setopt中添加CURLOPT_HTTPHEADER

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