= $sys['size'] && $i < $depth) {
    $size /= $sys['size'];
    $i++;
  }
  return sprintf($retstring, $size, $sys['prefix'][$i]);
}
// Respect HTTPS or not
if (isset($_SERVER['HTTPS'])) {
  $url = preg_replace("/^http:\/\//", "https://", $url);
} else {
  $url = preg_replace("/^https:\/\//", "http://", $url);
}
if ($_FILES["file"]["error"] > 0) {
  echo "Return Code: " . $_FILES["file"]["error"] . "
";
} else {
  if (file_exists($_FILES["file"]["name"])) {
    echo "Error: " . $_FILES["file"]["name"] . " already exists. ";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "./" . $_FILES["file"]["name"]);
    echo "Uploaded: " . $_FILES["file"]["name"] . "
";
    $fileurl = "$url" . $_FILES["file"]["name"];
    echo "URL: $fileurl
";
    echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi");
    if (isset($posturl)) {
      send_upload_notification($fileurl, $posturl, $postchannel);
    }
  }
}
function send_upload_notification($fileurl, $posturl, $channel) {
  $data = array('url' => $fileurl, 'channel' => $channel);
  $options = array(
    'http' => array(
      'header'  => "Content-type: application/x-www-form-urlencoded\r\n" .
                   "X-Blaears-Event: blaupload\r\n",
      'method'  => 'POST',
      'content' => http_build_query($data),
    ),
  );
  $context  = stream_context_create($options);
  file_get_contents($posturl, false, $context);
}
?>