$contents =<<
上传文件在数据报中应该是
Content-Disposition: form-data; name="file1"; filename="3.txt"
Content-Type: 文档类型
文件内容
TEXT;
$varname = 'file1';
$name = '3.txt';
$type = 'text/plain';
$key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\nAccept: \"";
$fields[$key] = $contents;
$fields['dd'] = "pupu";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://10.16.15.225/qa/test1.php");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$s = curl_exec ($ch);
curl_close ($ch);
echo $s;
?>
服务端$_POST数组结果:
array(1) { ["dd"]=> string(4) "pupu" }
$_FILES数组结果:
array(1) { ["file1"]=> array(5) { ["name"]=> string(5) "3.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpI7dkkA" ["error"]=> int(0) ["size"]=> int(380) } }