I am trying to send a png image from my server to a website via post request but it doesn't work. The website prompts me that it didn't receive any image.
Here's what I've tried so far...:
$ch = curl_init();
$imgpath = realpath("myimage.png");
$opts = array(CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array("uploadedfile" => '@' . $imgpath)
);
curl_setopt_array($ch, $opts);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
also
$opts = array(CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array("uploadedfile" => '@myimage.png')
);
and
$fp = fopen('myimage.png', 'r');
$opts = array(CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array("uploadedfile" => $fp)
);
but none of these worked. Can someone please guide me through the basic method (methods) of sending an image file via post request suing the curl?
Btw, realpath()
returns correct path, I've already checked it. The image is in the same directory where that script is located.