'); $req->addChild('userid', MY_ID); $req->addChild('userkey', MY_KEY); $req->addChild('action', 'AddMedia'); $req->addChild('source', $_POST['source']); $formatNode = $req->addChild('format'); // Format fields foreach($_POST['format'] as $property => $value) { if ($value !== '') $formatNode->addChild($property, $value); } // Sending API request $res = sendRequest($req->asXML()); try { // Creating new object from response XML $response = new SimpleXMLElement($res); // If there are any errors, set error message if(isset($response->errors[0]->error[0])) { $error = $response->errors[0]->error[0] . ''; } else if ($response->message[0]) { // If message received, set OK message $message = $response->message[0] . ''; } } catch(Exception $e) { // If wrong XML response received $error = $e->getMessage(); } // Displaying error if any if (!empty($error)) { echo '
' . htmlspecialchars($error) . '
'; } // Displaying message if (!empty($message)) { echo '
' . htmlspecialchars($message) . '
'; } exit; }