$file = count($arg["_"]) ? $arg["_"][0] : "-";
if ($file === "-") {
    $content = stream_get_contents(STDIN);
} else {
    $content = file_get_contents($file);
}
if ($content === false) {
    fwrite(STDERR, "{$file}: Read error\n");
    exit(1);
}
$docclass = new HotCRPDocument((int) $arg["d"]);
$docclass->set_no_database_storage();
if (isset($arg["no-file-storage"])) {
    $docclass->set_no_file_storage();
}
$docinfo = (object) array("paperId" => (int) $arg["p"]);
$doc = (object) array("content" => $content, "documentType" => (int) $arg["d"]);
if (@$arg["f"]) {
    $doc->filename = $arg["f"];
}
if (@$arg["m"]) {
    $doc->mimetype = $arg["m"];
} else {
    if ($m = Mimetype::sniff($doc->content)) {
        $doc->mimetype = $m;
    } else {
        $doc->mimetype = "application/octet-stream";
    }
}
$docclass->store($doc, $docinfo);