Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 发送带有卷曲的图像_Php_Curl - Fatal编程技术网

Php 发送带有卷曲的图像

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

是否可以发送带有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_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