当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::mimetype方法代码示例

本文整理汇总了PHP中Filesystem::mimetype方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::mimetype方法的具体用法?PHP Filesystem::mimetype怎么用?PHP Filesystem::mimetype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filesystem的用法示例。


在下文中一共展示了Filesystem::mimetype方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _compile


//.........这里部分代码省略.........
     }
     // LaTeX file?
     if ($tex && !empty($view->data)) {
         // Clean up data from Windows characters - important!
         $view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data);
         // Compile and get path to PDF
         $contentFile = $compiler->compileTex($file->get('fullPath'), $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase);
         // Read log (to show in case of error)
         $logFile = $tempBase . '.log';
         if (file_exists(PATH_APP . $outputDir . DS . $logFile)) {
             $view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile);
         }
         if (!$contentFile) {
             $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED'));
         }
     } elseif ($file->get('converted') && !empty($view->data)) {
         $tempBase = \Components\Projects\Helpers\Google::getImportFilename($file->get('name'), $cExt);
         // Write content to temp file
         $this->_connect->fetchFile($view->data, $tempBase, PATH_APP . $outputDir);
         $contentFile = $tempBase;
     } elseif (!$this->getError()) {
         // Make sure we can handle preview of this type of file
         if ($file->get('ext') == 'pdf' || $file->isImage() || !$file->isBinary()) {
             Filesystem::copy($file->get('fullPath'), PATH_APP . $outputDir . DS . $tempBase);
             $contentFile = $tempBase;
         }
     }
     $url = $this->model->link('files');
     $url .= $this->repo->isLocal() ? '' : '&repo=' . $this->repo->get('name');
     $url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : '';
     // Parse output
     if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) {
         // Get compiled content mimetype
         $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile);
         // Is image?
         if (strpos($cType, 'image/') !== false) {
             // Fix up object width & height
             list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile);
             $xRatio = $view->oWidth / $width;
             $yRatio = $view->oHeight / $height;
             if ($xRatio * $height < $view->oHeight) {
                 // Resize the image based on width
                 $view->oHeight = ceil($xRatio * $height);
             } else {
                 // Resize the image based on height
                 $view->oWidth = ceil($yRatio * $width);
             }
         }
         // Download compiled file?
         if ($download) {
             $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile);
             // Serve up file
             $server = new \Hubzero\Content\Server();
             $server->filename(PATH_APP . $outputDir . DS . $contentFile);
             $server->disposition('attachment');
             $server->acceptranges(false);
             $server->saveas($pdfName);
             $result = $server->serve_attachment(PATH_APP . $outputDir . DS . $contentFile, $pdfName, false);
             if (!$result) {
                 // Should only get here on error
                 App::abort(404, Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'));
             } else {
                 exit;
             }
         }
         // Add compiled PDF to repository?
开发者ID:kevinwojo,项目名称:hubzero-cms,代码行数:67,代码来源:files.php

示例2: compile

 /**
  * Compiles PDF/image preview for any kind of file
  *
  * @return  string
  */
 public function compile()
 {
     // Combine file and folder data
     $items = $this->getCollection();
     // Incoming
     $download = Request::getInt('download', 0);
     // Check that we have compile enabled
     // @FIXME: why are latex and compiled preview tied together?
     //         presumedly we are also 'compiling' pdfs?
     if (!$this->params->get('latex')) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_COMPILE_NOTALLOWED'));
         return;
     }
     // Output HTML
     $view = new \Hubzero\Plugin\View(['folder' => 'projects', 'element' => 'files', 'name' => 'connected', 'layout' => 'compiled']);
     // Make sure we have an item
     if (count($items) == 0) {
         $view->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_COMPILE'));
         $view->loadTemplate();
         return;
     }
     // We can only handle one file at a time
     $file = $items->first();
     // Build path for storing temp previews
     $imagePath = trim($this->model->config()->get('imagepath', '/site/projects'), DS);
     $outputDir = DS . $imagePath . DS . strtolower($this->model->get('alias')) . DS . 'compiled';
     // Make sure output dir exists
     if (!is_dir(PATH_APP . $outputDir)) {
         if (!Filesystem::makeDirectory(PATH_APP . $outputDir)) {
             $this->setError(Lang::txt('PLG_PROJECTS_FILES_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return;
         }
     }
     // Get LaTeX helper
     $compiler = new \Components\Projects\Helpers\Compiler();
     // Tex compiler path
     $texPath = DS . trim($this->params->get('texpath'), DS);
     // Set view args and defaults
     $view->file = $file;
     $view->oWidth = '780';
     $view->oHeight = '460';
     $view->url = $this->model->link('files');
     $cExt = 'pdf';
     // Tex file?
     $tex = $compiler->isTexFile($file->getName());
     // Build temp name
     $tempBase = $tex ? 'temp__' . \Components\Projects\Helpers\Html::takeOutExt($file->getName()) : $file->getName();
     $tempBase = str_replace(' ', '_', $tempBase);
     $view->data = $file->isImage() ? NULL : $file->read();
     // LaTeX file?
     if ($tex && !empty($view->data)) {
         // Clean up data from Windows characters - important!
         $view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data);
         // Store file locally
         $tmpfile = PATH_APP . $outputDir . DS . $tempBase;
         file_put_contents($tmpfile, $view->data);
         // Compile and get path to PDF
         $contentFile = $compiler->compileTex($tmpfile, $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase);
         // Read log (to show in case of error)
         $logFile = $tempBase . '.log';
         if (file_exists(PATH_APP . $outputDir . DS . $logFile)) {
             $view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile);
         }
         if (!$contentFile) {
             $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED'));
         }
         $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile);
     } else {
         // Make sure we can handle preview of this type of file
         if ($file->hasExtension('pdf') || $file->isImage() || !$file->isBinary()) {
             $origin = $this->connection->provider->alias . '://' . $file->getPath();
             $dest = 'compiled://' . $tempBase;
             // Do the copy
             Manager::adapter('local', ['path' => PATH_APP . $outputDir . DS], 'compiled');
             Manager::copy($origin, $dest);
             $contentFile = $tempBase;
         }
     }
     // Parse output
     if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) {
         // Get compiled content mimetype
         $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile);
         // Is image?
         if (strpos($cType, 'image/') !== false) {
             // Fix up object width & height
             list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile);
             $xRatio = $view->oWidth / $width;
             $yRatio = $view->oHeight / $height;
             if ($xRatio * $height < $view->oHeight) {
                 // Resize the image based on width
                 $view->oHeight = ceil($xRatio * $height);
             } else {
                 // Resize the image based on height
                 $view->oWidth = ceil($yRatio * $width);
             }
//.........这里部分代码省略.........
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:101,代码来源:connections.php

示例3: setMimeType

 /**
  * Set mime type
  *
  * @return  mixed
  */
 public function setMimeType()
 {
     if (!$this->get('mimeType')) {
         $this->set('mimeType', Filesystem::mimetype($this->get('fullPath')));
     }
 }
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:11,代码来源:file.php

示例4: getChanges

 /**
  * Get changes for sync
  *
  * @return     array
  */
 public function getChanges($localPath = '', $synced = '', $localDir = '', &$localRenames, $connections)
 {
     // Collector array
     $locals = array();
     // Initial sync
     if ($synced == 1) {
         $files = $this->callGit('ls-files --full-name ' . escapeshellarg($localDir));
         $files = empty($files) || substr($files[0], 0, 5) == 'fatal' ? array() : $files;
         if (empty($files)) {
             return $locals;
         }
         foreach ($files as $filename) {
             $type = 'file';
             // We are only interested in last local change on the file
             if (!isset($locals[$filename])) {
                 $time = strtotime(date('c', time()));
                 // Important! needs to be local time, NOT UTC
                 $locals[$filename] = array('status' => 'A', 'time' => $time, 'type' => $type, 'remoteid' => 0, 'converted' => 0, 'rParent' => NULL, 'local_path' => $filename, 'title' => basename($filename), 'author' => NULL, 'modified' => gmdate('Y-m-d H:i:s', $time), 'synced' => NULL, 'fullPath' => $localPath . DS . $filename, 'mimeType' => Filesystem::mimetype($localPath . DS . $filename), 'md5' => NULL, 'rename' => NULL);
             }
         }
     } else {
         // Collect
         $since = $synced != 1 ? ' --since="' . $synced . '"' : '';
         $where = $localDir ? '  --all -- ' . escapeshellarg($localDir) . ' ' : ' --all ';
         $changes = $this->callGit('rev-list ' . $where . $since);
         // Empty repo or no changes?
         if (empty($changes) || trim(substr($changes[0], 0, 5)) == 'usage') {
             $changes = array();
         }
         // Parse Git file list to find which items changed since last sync
         if (count($changes) > 0) {
             $timestamps = array();
             // Get files involved in each commit
             foreach ($changes as $hash) {
                 // Get time and author of commit
                 $time = $this->gitLog('', $hash, 'timestamp');
                 $author = $this->gitLog('', $hash, 'author');
                 // Get filename and change
                 $fileinfo = $this->callGit('diff --name-status ' . $hash . '^ ' . $hash);
                 // First commit
                 if (!empty($fileinfo) && !empty($fileinfo[0]) && substr($fileinfo[0], 0, 5) == 'fatal') {
                     $fileinfo = $this->callGit('log --pretty=oneline --name-status --root');
                     if (!empty($fileinfo)) {
                         // Remove first line
                         array_shift($fileinfo);
                     }
                 }
                 if (empty($fileinfo)) {
                     continue;
                 }
                 // Go through files
                 foreach ($fileinfo as $line) {
                     $n = substr($line, 0, 1);
                     if ($n == 'f') {
                         // First file in repository
                         $finfo = $this->callGit('log --pretty=oneline --name-status ' . $hash);
                         $status = 'A';
                         $filename = trim(substr($finfo[1], 1));
                         break;
                     } else {
                         $status = $n;
                         $filename = trim(substr($line, 1));
                     }
                     $type = 'file';
                     $rename = '';
                     // Detect a rename
                     if (isset($localRenames[$filename])) {
                         $rename = $localRenames[$filename];
                     } else {
                         $rename = $this->getRename($filename, $hash, $since);
                         if ($rename && $status == 'A') {
                             // Rename or move?
                             if (basename($rename) == basename($filename)) {
                                 $status = 'W';
                                 // this means 'move'
                             } else {
                                 $status = 'R';
                             }
                             $localRenames[$filename] = $rename;
                         }
                     }
                     // Hidden file in local directory - treat as directory
                     if (preg_match("/.gitignore/", $filename)) {
                         $filename = dirname($filename);
                         // Skip home directory
                         if ($filename == '.') {
                             continue;
                         }
                         $type = 'folder';
                     }
                     // Specific local directory is synced?
                     $lFilename = $localDir ? preg_replace("/^" . $localDir . "\\//", "", $filename) : $filename;
                     $conn = isset($connections['paths']) ? $connections['paths'] : NULL;
                     $search = $status == 'R' || $status == 'W' ? $rename : $filename;
                     $found = isset($conn[$search]) && $conn[$search]['type'] == $type ? $conn[$search] : false;
//.........这里部分代码省略.........
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:101,代码来源:githelper.php


注:本文中的Filesystem::mimetype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。