function post_data($datastream, $url, $file)
{
$originalurl=$url;
if (substr($originalurl, 0, 5) == "https") {
$protocol = "https";
$url = preg_replace("@^https://@i", "", $url);
$port = 443;
} else {
$protocol = "http";
$url = preg_replace("@^http://@i", "", $url);
$port = 80;
}
$host = substr($url, 0, strpos($url, "/"));
$uri = strstr($url, "/");
$reqbody = "";
foreach($datastream as $key=>$val) {
if( is_array($val)){ //don't url encode if we're passing an array
if (!empty($reqbody)) $reqbody .= "&";
$reqbody .= $key."=".$val;
}else{
if (!empty($reqbody)) $reqbody .= "&";
$reqbody .= $key."=".urlencode($val);
// echo $reqbody;
}
}
$reqlength = strlen($reqbody);
$uri=$uri."/".$file;
$reqheader = "POST $uri HTTP/1.0\r\n".
"Host: $host\r\n" . "User-Agent: CK-Conception POST-o-matic\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-type: text/xml\r\n".
"Content-Length: $reqlength\r\n\r\n".
"$reqbody\r\n";
if (substr($originalurl, 0, 5) == "https") {
$socket = fsockopen("ssl://" . $host, $port, $errno, $errstr);
} else {
$socket = fsockopen($host, $port, $errno, $errstr);
}
if (!$socket) {
$result["errno"] = $errno;
$result["errstr"] = $errstr;
return $result;
}
fputs($socket, $reqheader);
while (!feof($socket)) {
$result[] = fgets($socket, 4096);
}
fclose($socket);
return $result;
}