我生成一些XML(實際上谷歌KML文件)POST使用捲曲不同的數據類型
$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數據
//設置捲曲
$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」]);返回空嗎?
-Am我在這裏錯過了什麼? - 我可以發送兩種類型的數據嗎?
你有沒有試過的multipart/form-data的頭? – FrediWeber
否;我不確定你的意思?我如何設置標題? – Thomas