php - Send an image with CURL -


is possible send image curl outputs imagepng?

ob_start(); imagepng(imagecreatetruecolor(800, 600)); $file = ob_get_clean();  $curl = curl_init(); curl_setopt($curl, curlopt_url, $remotehost); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, [     'file1' => ? ]); curl_setopt($curl, curlopt_returntransfer, 1); $contents = curl_exec($curl); curl_close($curl); 

thank you!

you need put @ character before file path, , path must full path.

curl_setopt($curl, curlopt_postfields, array(     'file1' => '@' . '/var/tmp/img.png' )); 

if request accepts image inside post body raw data, case can place inside post mentioning whatever content-type requires.

$image_data = file_get_contents('/var/tmp/img.png'); curl_setopt($curl, curlopt_postfields, $image_data); curl_setopt($curl, curlopt_httpheader, array('content-type: text/plain'));  // example 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -