简体   繁体   English

用php curl上传文件

[英]Upload a file with php curl

Sending the wrong mime-type. 发送错误的mime类型。 the file type "video/mp4" but "application / octet-stream" as the sending. 文件类型为“ video / mp4”,但发送类型为“ application / octet-stream”。 I want to send "video/mp4". 我想发送“视频/ mp4”。 Curl option($file = real path) 卷曲选项($ 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 debugger Out HTTP调试器

------------------------------94a50e65d9fe Content-Disposition: form-data; ------------------------------ 94a50e65d9fe内容处置:表单数据; name="videoupload" name =“ videoupload”

1 ------------------------------94a50e65d9fe Content-Disposition: form-data; 1 ------------------------------ 94a50e65d9fe Content-Disposition:表单数据; name="input_1"; name =“ input_1”; filename="1.mp4" Content-Type: application/octet-stream filename =“ 1.mp4”内容类型:application / octet-stream

I've tried it 我试过了

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

failed creating formpost data 创建formpost数据失败

尝试像这样在curl_setopt中添加CURLOPT_HTTPHEADER

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM