我生成了一些 xml(实际上是 google kml 文件)
$kml = array('<?xml version="1.0" encoding="UTF-8"?>');
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
$kml[] = ' <Document>';
我把它串起来
$kmlOutput = implode("\n", $kml); //Join array elements with a string
然后我做一个数组
$data = array('code' => 'somecode', 'xml' => $kmlOutput);
然后我发送我的 cURL 数据
// 设置 cURL
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
$output = curl_exec($ch);
/**
* Check for some errors (omitted here)
*/
curl_close($ch);
Upload.php 在另一台服务器上
/* MAIN CODE*/
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
print "\n\n";
echo "DEBUG: Vardump Post";
var_dump($_POST);
echo "DEBUG:";
var_dump($_FILES);
if ($_FILES["file"]["type"] == "text/xml" && ($_FILES["file"]["size"] < $maxSize) ){
if ($_FILES["file"]["error"] > 0){
echo "Error: (Return Code: " . $_FILES["file"]["error"] . ")<br />";
} else {
echo "Code: ".$_POST['key']. "<br />";
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp Stored in: " . $_FILES["file"]["tmp_name"]. "<br />"; // temporary copied files disappears when the script ends
move_uploaded_file($_FILES["file"]["tmp_name"],$dir . $_FILES["file"]["name"]);
echo "Stored in: " . $dir . $_FILES["file"]["name"];
但是 var_dump($_FILES); 甚至 var_dump($_FILES["code"]); 返回空?
-我在这里错过了什么吗?- 我可以发送两种类型的数据吗?