0

currently using php 7.4.

i have the following form:

<form id="image" method="post" action="/api">
<input name="username" type="text">
<input name="image" type="file">
<input type="submit" value="submit">
</form>

i need to send the file received from the form to another server without saving it on the 1st server.

i have found new CURLFile(); and curl_file_create(); but i don't know how to work with them.

this is my php curl code to send, and FYI, the curl sends username without any problem.

if($_FILES['image'] ){
            $img = // new CURLFile() or curl_file_create();
}else{
            $img = '';
}
$headers = array("Content-Type" => "multipart/form-data");
$ch = curl_init();
$pdata = array(
            'username' => $_REQUEST['username'],
            'image'    => $img
);

curl_setopt($ch, CURLOPT_URL,"API url");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);
curl_errno($ch);

curl_close ($ch);

what should i do? and what is it that i have to write inside new CURLFile(); orcurl_file_create();?!

p.s. i have seen curl_file_create('path/to/image'); but i don't know what path/to/image is!

any help would be appreciated,

thanks in advance!

KoCo
  • 1
  • 1

0 Answers0