0

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.

kittykittybangbang
  • 2,380
  • 4
  • 16
  • 27
  • you can always check request/response headers in PHP. https://stackoverflow.com/questions/3164405/show-curl-post-request-headers-is-there-a-way-to-do-this – mehulmpt Mar 21 '17 at 16:18
  • I checked, it says [size_upload] => 98710 bytes 0.09 MB but my file is 5511326 bytes 5.5 mb – ForWhhY Mar 21 '17 at 16:32
  • is your script time out limit short? – mehulmpt Mar 21 '17 at 16:34
  • @MehulMohan Here is my limit, using this limit on another upload files without any issue. `ini_set('max_execution_time', 1800);` `ini_set('display_errors', 1);` `ini_set('display_startup_errors', 1);` `error_reporting(E_ALL);` – ForWhhY Mar 21 '17 at 16:38
  • Possible duplicate of [PHP Curl upload, post values in order as set in array](http://stackoverflow.com/questions/42940301/php-curl-upload-post-values-in-order-as-set-in-array) – miken32 Mar 24 '17 at 05:04

0 Answers0