I'm writing an API and I'm wanting to uploads from a form POST.
this is my html form
<form method="post" action = 'function.php' enctype="multipart/form-data">
<input type = 'file' name = 'pictures' required>
<input type = 'submit'/>
this is my function.php
$uploads_dir = 'img/BL/';
$tmp_name = $_FILES["pictures"]["tmp_name"];
$name = $_FILES["pictures"]["name"];
$asd = move_uploaded_file($tmp_name, "$uploads_dir/$name");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.example.com/upload/images.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $asd,
CURLOPT_HTTPHEADER => array(
"authorization: Basic NDM0MDY1Mzc6TE9sSmV1V003aTg2a2x6Mw==",
"cache-control: no-cache",
"content-type: multipart/form-data",
"postman-token: a88b550a-3544-85b7-ca6b-1ed8cc5cb35c"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
// echo $name;
}
and response from API is
{
status: "ERROR",
id: null,
message: "must have an image"
}
the problem is images already save but when i try to upload using cURL get response "Harus ada file gambar" (Must have image) the image isnt read/detected when upload
am I going about this the wrong way? Any advice would be most appreciated. Maybe someone can tell me the clue, or whats wrong with my code, thank you