POST using cURL different data types

Claiginaloden

New Member
I generate some xml (actually google kml file)\[code\]$kml = array('<?xml version="1.0" encoding="UTF-8"?>');$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';$kml[] = ' <Document>';\[/code\]I make a string of it\[code\]$kmlOutput = implode("\n", $kml); //Join array elements with a string\[/code\]Then I make an array\[code\]$data = http://stackoverflow.com/questions/12780962/array('code' => 'somecode', 'xml' => $kmlOutput);\[/code\]Then I send my data of cURL// Setup cURL\[code\]$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);\[/code\]Upload.php on another server\[code\]/* 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"];\[/code\]However the var_dump($_FILES); and even var_dump($_FILES["code"]); return empty?-Am I missing something here?-Can I send two types of data?edit (complete code after edit proposed):\[code\]<?php /* SETTINGS */$username = 'root';$password = '';$database = 'coptermotion';$server = 'localhost';$URL = "..";// Opens a connection to a MySQL server.$connection = mysql_connect ($server, $username, $password);if (!$connection) { die('Not connected : ' . mysql_error());}// Sets the active MySQL database.$db_selected = mysql_select_db($database, $connection);if (!$db_selected) { die('Can\'t use db : ' . mysql_error());}// Selects all the rows in the markers table.$query = 'SELECT * FROM markers WHERE 1';$result = mysql_query($query);if (!$result) { die('Invalid query: ' . mysql_error());}// Creates an array of strings to hold the lines of the KML file.$kml = array('<?xml version="1.0" encoding="UTF-8"?>');$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';$kml[] = ' <Document>';// Iterates through the rows, printing a node for each row.while ($row = @mysql_fetch_assoc($result)) { $kml[] = ' <Placemark id="placemark' . $row['id'] . '">'; // $kml[] = ' <name>' . htmlentities($row['name']) . '</name>'; // $kml[] = ' <description>' . htmlentities($row['address']) . '</description>'; // $kml[] = ' <styleUrl>#' . ($row['type']) .'Style</styleUrl>'; $kml[] = ' <Point>'; $kml[] = ' <coordinates>' . $row['lng'] . ',' . $row['lat'] . '</coordinates>'; $kml[] = ' </Point>'; $kml[] = ' </Placemark>';} // End XML file$kml[] = ' </Document>';$kml[] = '</kml>';$kmlOutput = implode("\n", $kml); //Join array elements with a string// Setup cURL$ch = curl_init($URL);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $kmlOutput);curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_TIMEOUT, 8);// Execute cURL (Send XML file to receiving 'upload.php' on the server side$output = curl_exec($ch);/** * Check for errors */if ( curl_errno($ch) ) { $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);} else { $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); switch($returnCode){ case 404: $result = 'ERROR -> 404 Not Found'; break; default: break; }}/** * Close the handle */curl_close($ch);print $output;?>\[/code\]
 
Back
Top