//
// Sample Web form demonstrating file upload to Siets server using HTTP API built-in
// conversion tool
//
header('content-type: text/html; charset=utf-8');
// stupid quotes
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
}
$_GET = array_map('stripslashes_deep', $_GET);
$_POST = array_map('stripslashes_deep', $_POST);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
function http_post($u, $headers, $data)
{
if (is_string($u)) $u = parse_url($u);
if (!$u['port']) $u['port'] = 80;
if (!$u['path']) $u['path'] = '/';
$request = "POST " . $u['path'] . '?' . $u['query'] . " HTTP/1.0\r\nHost: " . $u['host'] . "\r\n$headers\r\n$data\r\n\r\n";
$response = FALSE;
$f = fsockopen($u['host'], $u['port']);
if ($f) {
fputs($f, $request);
while (!feof($f)) $response .= fgets($f, 4096);
fclose($f);
}
return $response;
}
function xml_esc($str)
{
return htmlspecialchars($str, ENT_QUOTES, 'utf-8');
}
if (!isset($_POST['b'])) {
// form initialization
$p = 'http://127.0.0.1/cgi-bin/siets/api.cgi';
$s = 'test';
$t = '';
$display_reply = FALSE;
} else {
// POST data received
$p = $_POST['p'];
$s = $_POST['s'];
$t = $_POST['t'];
$enc = 'utf-8';
$f = $_FILES['f'];
$display_reply = TRUE;
if ($f['error'] === UPLOAD_ERR_OK) {
// pass file extension as its type
if (($extpos = strrpos($f['name'], '.')) === FALSE) {
$ext = '';
} else {
$ext = substr($f['name'], $extpos + 1);
}
// format XML command (conversion works with update command too)
$data = '