function kfmFile() { global $kfm; if (func_num_args() == 1) { $this->id = (int) func_get_arg(0); parent::__construct(); $filedata = db_fetch_row("SELECT id,name,directory FROM " . KFM_DB_PREFIX . "files WHERE id=" . $this->id); $this->name = $filedata['name']; $this->parent = $filedata['directory']; $dir = kfmDirectory::getInstance($this->parent); $this->dir = $dir; $this->directory = $dir->path(); $this->path = $this->directory . '/' . $filedata['name']; if (!$this->exists()) { // $this->error(kfm_lang('File cannot be found')); // removed because it is causing false errors $this->delete(); return false; } $this->writable = $this->isWritable(); $this->ctime = filemtime($this->path) + $GLOBALS['kfm_server_hours_offset'] * 3600; $this->modified = strftime($kfm->setting('date_format') . ' ' . $kfm->setting('time_format'), filemtime($this->path)); $mimetype = Mimetype::get($this->path); $pos = strpos($mimetype, ';'); $this->mimetype = $pos === false ? $mimetype : substr($mimetype, 0, $pos); $this->type = trim(substr(strstr($this->mimetype, '/'), 1)); } }
/** * Get all temporary images in session * * @return array */ public function all() { $dir = public_path() . '/uploads/temp/' . Session::getId() . '/'; $data = []; $mimetypes = new Mimetype(); if (file_exists($dir)) { foreach (scandir($dir) as $file) { if (in_array($file, ['.', '..'])) { continue; } $filedata = []; $filedata['name'] = $file; $filedata['url'] = url('/uploads/temp/' . Session::getId() . '/' . $file); $filedata['size'] = File::size($dir . $file); $filedata['type'] = $mimetypes->detectByFileExtension(File::extension($file)); $data[] = $filedata; } return $data; } }
/** * Faz o stream do arquivo. * * @throws Exception */ public function streamFile() { $mimetype = $this->Mimetype->getType($this->filepath); if (FALSE === $mimetype) { throw new Exception('Extensão não suportada.'); } // Headers para stream de arquivo header('Content-Description: File Transfer'); header('Content-Type: ' . $mimetype); header('Content-Disposition: attachment; filename=' . basename($this->filepath)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($this->filepath)); ob_clean(); flush(); // Lê o arquivo para stream buffer readfile($this->filepath); }
echo urlencode($attachment['url']); ?> &width=300&showstop=0&showinfo=0&showvolume=1&showloading=autohide&volumewidth=40&bgcolor1=E4E5FF&bgcolor2=D4D6FF&slidercolor1=#3F3D6A&slidercolor2=242153&sliderovercolor=15123C&buttoncolor=242153&buttonovercolor=15123C&textcolor=242153"/> </object> <?php break; // Document // Document default: ?> <div class="attachment"> <a href="<?php echo $attachment['url']; ?> "><img src="<?php echo Mimetype::getIcon($attachment['ext']); ?> " alt="" class="icon" /> <?php echo htmlspecialchars($attachment['name']); ?> </a> </div> <?php } } // Si on affiche uniquement ce post, on prépare l'affichage des photos en grand if (isset($one_post) && $post['attachments_nb_photos'] != 0) { ?> <div id="attachment-photo" class="hidden"> <a href="javascript:;" id="attachment-photo-prev"><?php echo __('POST_PHOTO_PREV');
return $x && $x->mimetypeid <= 2; } static function sniff($content) { if (strncmp("%PDF-", $content, 5) == 0) { return self::type("pdf"); } else { if (strncmp("%!PS-", $content, 5) == 0) { return self::type("ps"); } else { if (substr($content, 512, 4) == "nð") { return self::type("ppt"); } else { return null; } } } } } Mimetype::register(Mimetype::TXT, "text/plain", ".txt", "text"); Mimetype::register(Mimetype::PDF, "application/pdf", ".pdf", "PDF"); Mimetype::register(3, "application/postscript", ".ps", "PostScript"); Mimetype::register(4, "application/vnd.ms-powerpoint", ".ppt", "PowerPoint"); Mimetype::register(5, "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".pptx", "PowerPoint"); Mimetype::register(6, "video/mp4", ".mp4"); Mimetype::register(7, "video/x-msvideo", ".avi"); Mimetype::register(8, "application/json", ".json"); Mimetype::register_synonym("application/mspowerpoint", "application/vnd.ms-powerpoint"); Mimetype::register_synonym("application/powerpoint", "application/vnd.ms-powerpoint"); Mimetype::register_synonym("application/x-mspowerpoint", "application/vnd.ms-powerpoint");
// { headers if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { $name = preg_replace('/\\./', '%2e', $name, substr_count($name, '.') - 1); } @set_time_limit(0); header('Cache-Control: max-age = 2592000'); header('Expires-Active: On'); header('Expires: Fri, 1 Jan 2500 01:01:01 GMT'); header('Pragma:'); $filesize = filesize($path); header('Content-Length: ' . (string) filesize($path)); if (isset($_GET['forcedownload'])) { header('Content-Type: force/download'); header('Content-Disposition: attachment; filename="' . $name . '"'); } else { header('Content-Type: ' . Mimetype::get($extension)); } header('Content-Transfer-Encoding: binary'); // } if ($file = fopen($path, 'rb')) { // send file while (!feof($file) && connection_status() == 0) { print fread($file, 1024 * 8); flush(); } fclose($file); } if (file_exists('api/log_retrieved_file.php')) { require 'api/log_retrieved_file.php'; } return connection_status() == 0 and !connection_aborted();
public static function render($templateName, $directory, $options = NULL) { $template = new Template($templateName, $directory, $options); if (isset($options['header']) && $options['header']) { header('Content-Type: ' . Mimetype::fromExtension($this->getExtension())); } if (isset($options['relative']) && $options['relative']) { return $template->getParsedRelativePath(); } else { return $template->getParsedPath(); } }
public function renderFile($filePath, $download = FALSE) { $this->setIsRendered(true); if (!file_exists($filePath)) { throw new InvalidViewException("`{$filePath}` was not found on the server"); } $extension = substr(strrchr($filePath, "."), 1); header('Content-Type: ' . Mimetype::fromPath($filePath)); if ($download) { header('Content-Disposition: attachment; filename=' . basename($filePath)); } header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filePath)); echo readfile($filePath); }
function download_headers($downloadname = null, $attachment = null) { if ($this->is_csv()) { header("Content-Type: text/csv; charset=utf-8; header=" . ($this->headerline !== "" ? "present" : "absent")); } else { header("Content-Type: text/plain; charset=utf-8"); } if ($attachment === null) { $attachment = !Mimetype::disposition_inline($this->is_csv() ? "text/csv" : "text/plain"); } if (!$downloadname) { $downloadname = "data" . $this->extension(); } header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname)); // reduce likelihood of XSS attacks in IE header("X-Content-Type-Options: nosniff"); }
private function _filestore($doc) { if (!($fsinfo = $this->filestore_pattern($doc)) || get($doc, "error")) { return $fsinfo; } list($fdir, $fpath) = $fsinfo; $sha1 = false; $xfpath = $fdir; $fpath = substr($fpath, strlen($fdir)); while (preg_match("/\\A(.*?)%(\\d*)([%hx])(.*)\\z/", $fpath, $m)) { $fpath = $m[4]; $xfpath .= $m[1]; if ($m[3] === "%") { $xfpath .= "%"; } else { if ($m[3] === "x") { $xfpath .= Mimetype::extension(self::_mimetype($doc)); } else { if ($sha1 === false) { $sha1 = self::text_sha1($doc); } if ($sha1 === false && ($content = self::content($doc)) !== false) { $sha1 = $doc->sha1 = sha1($content); } if ($sha1 === false) { return array(null, null); } if ($m[2] !== "") { $xfpath .= substr($sha1, 0, +$m[2]); } else { $xfpath .= $sha1; } } } } if ($fdir && $fdir[strlen($fdir) - 1] === "/") { $fdir = substr($fdir, 0, strlen($fdir) - 1); } return array($fdir, $xfpath . $fpath); }
} $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);
public static function s3_filename($doc) { if (($sha1 = Filer::text_sha1($doc)) !== false) { return "doc/" . substr($sha1, 0, 2) . "/" . $sha1 . Mimetype::extension($doc->mimetype); } else { return null; } }
} $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);
<?php /* * Created by Hei */ Router::listen('GET', DIRECTORY_PREFIX . '$controller:Controller', function ($request) { $url = SIMPHPFY_RELATIVE_PATH . $request->params['controller'] . '/Index'; header("location: {$url}"); die; }); Router::listen('GET', DIRECTORY_PREFIX . '__WebDocument/$base64:*', function ($request) { $file = base64_decode(urldecode($request->params['base64'])); if (!file_exists($file)) { throw new FileNotFoundException('File not found'); } header('Content-Type: ' . Mimetype::fromPath($file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; }); Router::listen(array('GET', 'POST', 'PUT', 'DELETE'), DIRECTORY_PREFIX . ':Controller/:Action'); Router::listen(array('GET', 'POST', 'PUT', 'DELETE'), DIRECTORY_PREFIX . ':Controller/:Action/$id:ID');
function downloadPaperName($paperId, $mimetype, $documentType) { global $Opt; $title = $Opt["downloadPrefix"]; $dtn = HotCRPDocument::unparse_dtype($documentType); $title .= $dtn ? $dtn : "xxx"; if (ctype_digit($title[strlen($title) - 1])) { $title .= "-"; } return $title . $paperId . Mimetype::extension($mimetype); }
function download_old($id) { $result = $this->FileLibraryFile->findById($id); if (empty($result)) { $this->_smartFlash('Sorry, that file was not found.', '/'); } elseif ($result['FileLibraryFile']['user_id'] != $this->Auth->user('id') && $this->Auth->user('administrator') != true) { $this->_smartFlash('Sorry, you don\'t have permission to download that file.', '/'); } else { $filepath = WWW_ROOT . 'files' . DS . $result['FileLibraryFile']['id'] . DS . $result['FileLibraryFile']['filename']; if (file_exists($filepath)) { // MimeType class distributed with Attachments Behaviour App::import('Vendor', 'Mimetype'); header('Content-type: ' . Mimetype::detectFast($filepath)); header('Content-Disposition: attachment; filename="' . $result['FileLibraryFile']['filename'] . '"'); readfile($filepath); exit; } else { $this->_smartFlash('Sorry, that file was not found.', '/'); } } }