1
votes

Sending the wrong mime-type. the file type "video/mp4" but "application / octet-stream" as the sending. I want to send "video/mp4". Curl option($file = real path)

$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

------------------------------94a50e65d9fe Content-Disposition: form-data; name="videoupload"

1 ------------------------------94a50e65d9fe Content-Disposition: form-data; name="input_1"; filename="1.mp4" Content-Type: 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:

failed creating formpost data

1
Don't you want CURLOPT_HTTPHEADER? See: stackoverflow.com/questions/356705/… - ficuscr
header is correct(Content-Type: multipart/form-data"). remote server checking file mime-type($_FILES['input_1']["type"]). - mollyjane
You might want to update the question to be more clear. Anyway, you never want to trust $_FILES[..]['type'] - Try and use something like finfo if you need to do this. - ficuscr
Http Debugger(Google Chrome):Content-type:multipart/form-data; tny.cz/d4a8fba5 Http Debugger(Curl): Content-type:multipart/form-data; tny.cz/acd09926 - mollyjane
Is this post ever going to help anyone else? Maybe OP can update the question and better explain the solution? I still don't even know I understand the question being asked. - ficuscr

1 Answers

0
votes

try adding CURLOPT_HTTPHEADER in curl_setopt like that

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