I want to upload a video file to a site. By default in browser I can upload videos but when I try to do this in php via curl something goes wrong because I do not receive the video code (vcode) in response.
Here is the XHR Request, this way is working, the original upload request:
  var formData = new FormData();
  formData.append("sid", "MYSID");
  formData.append("cmd", "uploadVideoFile");
  formData.append("uploadfile", uFile, uFile.name);
  var oXHR = new XMLHttpRequest();
  oXHR.open("POST", upload_url);
  oXHR.send(formData);
Request headers:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Content-Length  123456
Content-Type multipart/form-data; boundary=---------------------------26463276212588
Host    upload.somehost.com
Origin  http://somehost.com
Referer http://somehost.com/upload
User-Agent  Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Here is the POST:
    -----------------------------26463276212588
Content-Disposition: form-data; name="sid"
MYSID
-----------------------------26463276212588
Content-Disposition: form-data; name="cmd"
uploadVideoFile
-----------------------------26463276212588
Content-Disposition: form-data; name="uploadfile"; filename="test.mp4"
Content-Type: video/mp4
Response after post (When successful):
{"response":{"code":0,"vcode":"dBG5XL2VdibeKAG4"}}
This code is: dBG5XL2VdibeKAG4 which is what I'm not receiving if I upload the video via curl.
CURL PHP code:
$file = "/var/www/html/dl/big.mp4";
$data = array('sid' => 'MYSID', 'cmd' => 'uploadVideoFiles', 'uploadfile' => '@' . realpath($file));
$lenght = sizeof($data);
$request = curl_init('http://uploadurl/uploadpage');
curl_setopt($request, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0");
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($request, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
curl_setopt($request, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type:multipart/form-data',                                                                                
    'Content-Length: ' . strlen($lenght))                                                                       
);                       
echo curl_exec($request);
curl_close($request);
Response when I do not receive vcode:
{"response":{"code":0,"vcode":""}} 
So I think the CURL code is incorrect somewhere or I'm not sending the request the same way as the XHR sends it.