我希望这是有帮助的:
<?php
$headers = array('token: pacexpressx1x2x3j');
$data = array(
"STATUS" => "insert" ,
"NAME" => utf8_encode("Test integration 10"),
"COD_AREA" => "4",
"DESC_AREA_" => utf8_encode("info/IT"),
"JOB" => utf8_encode("TEST job"),
"COMPANY" => "4",
"DESC_COMPANY" => utf8_encode("XPTO1"),
"file" => '@/home/user/test.png');
$url = 'your_link';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
echo($output) . PHP_EOL;
curl_close($ch);
在这个例子中我发送一个报头,和后场。
$ headers =>我把一个标记值放在一个数组中,只是为了显示如何发送一个值。
$ data =>我用了一些具有想象值的数组。
在我用这个卷曲variebles这里: curl_setopt($ CH,CURLOPT_POSTFIELDS,$ data_string); curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
CURLOPT_POSTFIELDS - >要在HTTP“POST”操作中发布的完整数据。要发布文件,请使用@预先指定文件名并使用完整路径。文件类型可以通过跟随具有格式'; type = mimetype'格式的文件名来显式指定。此参数可以作为urlencoded字符串传递,如'para1 = val1 & para2 = val2 & ...'或作为字段名称作为键和字段数据作为值的数组。如果value是一个数组,则Content-Type头将被设置为multipart/form-data。从PHP 5.2.0开始,如果使用@前缀将文件传递给此选项,则值必须是数组。
如果您想了解更多关于curl_setopt,我sugest你这个链接: http://php.net/manual/pt_BR/function.curl-setopt.php
要看到你发送和接收您发送的文件,你可以波纹管使用此代码:
echo 'Here is some more debugging info:';
echo "\n<hr />\n";
print_r($_FILES);
echo "\n<hr />\n";
print_r($_POST);
print "</pr" . "e>\n";
echo "\n<hr />\n";
// here you will record the file in your server... you can choose a directory if you want
file_put_contents($_FILES['file']['name'],file_get_contents($_FILES['file']['tmp_name']));
你最好阅读关于CURL:http://php.net/curl。 – shadyyx