1

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

  • Don't you want `CURLOPT_HTTPHEADER`? See: http://stackoverflow.com/questions/356705/how-to-send-a-header-using-a-http-request-through-a-curl-call – ficuscr Mar 25 '13 at 19:25
  • header is correct(Content-Type: multipart/form-data"). remote server checking file mime-type($_FILES['input_1']["type"]). –  Mar 25 '13 at 19:33
  • 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`](http://www.php.net/manual/en/function.finfo-file.php) if you need to do this. – ficuscr Mar 25 '13 at 19:38
  • Http Debugger(Google Chrome):Content-type:multipart/form-data; http://tny.cz/d4a8fba5 Http Debugger(Curl): Content-type:multipart/form-data; http://tny.cz/acd09926 –  Mar 25 '13 at 20:33
  • I solved the problem. The problem is the windows. Php curl library not support in windows os. "Content-Type: multipart/form-data" Must define to header. –  Mar 25 '13 at 23:32
  • 1
    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 Mar 26 '13 at 15:40

1 Answers1

0

try adding CURLOPT_HTTPHEADER in curl_setopt like that

curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: video/mp4'));
kuldeep.kamboj
  • 2,566
  • 3
  • 26
  • 63
  • header is correct(Content-Type: multipart/form-data"). Because not only the video. Data is available. –  Mar 25 '13 at 21:05
  • Ok, but http://www.php.net/manual/en/curl.installation.php says, `In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH. You don't need libcurl.dll from the cURL site.`. Is really we need curl on windows to run php-curl ? – kuldeep.kamboj Mar 26 '13 at 05:11
  • But yes it can be possible if header content-type have different behavior on windows. – kuldeep.kamboj Mar 26 '13 at 05:16
  • I solved the problem. http://stackoverflow.com/questions/15622814/upload-a-file-with-php-curl/15623134?noredirect=1#comment22168318_15622814 –  Mar 26 '13 at 11:03