} $s3doc = HotCRPDocument::s3_document(); $ok = 0; foreach ($arg["_"] as $fn) { if ($fn === "-") { $content = @stream_get_contents(STDIN); } else { $content = @file_get_contents($fn); } if ($content === false) { $error = error_get_last(); $fn = $fn === "-" ? "<stdin>" : $fn; if (!$quiet) { echo "{$fn}: " . $error["message"] . "\n"; } $ok = 2; } else { $doc = (object) array("sha1" => sha1($content, true)); if (!($extensions && preg_match('/(\\.\\w+)\\z/', $fn, $m) && ($doc->mimetype = Mimetype::lookup_extension($m[1])))) { $doc->mimetype = Mimetype::sniff($content); } $s3fn = HotCRPDocument::s3_filename($doc); if (!$s3doc->check($s3fn)) { if (!$quiet) { echo "{$fn}: {$s3fn} not found\n"; } $ok = 1; } } } exit($ok);
function upload($doc, $docinfo) { global $Conf; if (is_object($doc)) { $doc = clone $doc; if (!$this->load($doc) && !get($doc, "error_html")) { set_error_html($doc, "The uploaded file was empty."); } } else { $doc = self::file_upload_json($doc); } if (get($doc, "error")) { return $doc; } // Check if paper one of the allowed mimetypes. if (!get($doc, "mimetype")) { $doc->mimetype = "application/octet-stream"; } // Sniff content since MacOS browsers supply bad mimetypes. if ($m = Mimetype::sniff(self::content($doc))) { $doc->mimetype = $m; } if ($m = Mimetype::lookup($doc->mimetype)) { $doc->mimetypeid = $m->mimetypeid; } $mimetypes = $this->mimetypes($doc, $docinfo); for ($i = 0; $i < count($mimetypes); ++$i) { if ($mimetypes[$i]->mimetype === $doc->mimetype) { break; } } if ($i >= count($mimetypes) && count($mimetypes)) { $e = "I only accept " . htmlspecialchars(Mimetype::description($mimetypes)) . " files."; $e .= " (Your file has MIME type “" . htmlspecialchars($doc->mimetype) . "” and starts with “" . htmlspecialchars(substr($doc->content, 0, 5)) . "”.)<br />Please convert your file to a supported type and try again."; return set_error_html($doc, $e); } if (!get($doc, "timestamp")) { $doc->timestamp = time(); } $this->store($doc, $docinfo); return $doc; }
} $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);