RESTful file upload in PHP

So, I am working on a script that will upload video to the server through the RESTful interface. The documentation tells me that I should transfer the data (including the binary video file) as part of the POST request. I know how to set my POST variables, but I'm not sure how to make binary data. The API says that I should have a field called "media" and it should contain raw video data.

So, let's say I have a video called 'video1.mp4' and I want to include its contents in my POST variable. How can i do this?

Thank!

+3
source share
1 answer

, API, cURL . CURLOPT_POSTFIELDS:

CURLOPT_POSTFIELDS
HTTP- "POST". , @ . urlencoded, "para1 = val1 & para2 = val2 &..." . , Content-Type multipart/form-data.

:

$ch = curl_init();

$data = array('name' => 'Foo', 'media' => '@/home/user/test.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
+5

Source: https://habr.com/ru/post/1753477/


All Articles