Php 发送带有卷曲的图像
是否可以发送带有CURL的图像,并输出带有ImagePNG的图像Php 发送带有卷曲的图像,php,curl,Php,Curl,是否可以发送带有CURL的图像,并输出带有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_POST
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);
谢谢大家! 只需将
@
字符放在文件路径之前,路径必须是完整路径
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
'file1' => '@' . '/var/tmp/img.png'
));
如果请求接受POST正文中的图像作为原始数据,那么您可以将其放置在POST
中,并提及它所需的任何内容类型
$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')); // just an example
您只需要在文件路径之前添加
@
字符,并且路径必须是完整路径
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
'file1' => '@' . '/var/tmp/img.png'
));
如果请求接受POST正文中的图像作为原始数据,那么您可以将其放置在POST
中,并提及它所需的任何内容类型
$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')); // just an example