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


PHP Media::getFilesPath方法代码示例

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


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

示例1: _writeLog

 private static function _writeLog($type, $module, $message)
 {
     $logFile = ROOT . Media::getFilesPath() . Config::get(sprintf('log.%s_file', $type));
     $logDir = implode('/', explode('/', $logFile, -1));
     if (!file_exists($logDir)) {
         $filesPath = ROOT . Media::getFilesPath();
         if (is_writable($filesPath)) {
             mkdir($logDir);
         } else {
             die('Unable to create log directory because your files directory isn\'t writable.');
         }
     }
     if (!is_writable($logDir)) {
         die('Unable to write log file because your log directory isn\'t writable.');
     }
     if (!file_exists($logFile)) {
         $header = "<?php if(!defined('ROOT')) exit; ?>\n";
         if (!($handle = fopen($logFile, 'a'))) {
             die('Cant create log file: ' . $logFile);
         }
         if (fwrite($handle, $header) === false) {
             die('Cant write to log file: ' . $logFile);
         }
         fclose($handle);
     }
     $log = sprintf("[%s] %s: %s\n", date('Y-m-d H:i:s'), $module, $message);
     if (!($handle = fopen($logFile, 'a'))) {
         die('Cant open log file for writing: ' . $logFile);
     }
     if (fwrite($handle, $log) === false) {
         die('Cant write to log file: ' . $logFile);
     }
     fclose($handle);
 }
开发者ID:simudream,项目名称:caffeine,代码行数:34,代码来源:log.php

示例2: render

 /**
  * Gets an image by id sized and rotated based on the passed params. If the file
  * doesn't exist, it is created using the imager class and stored in cache dir. Every 
  * call after that will load the file directly.
  *
  * When sizing an image with the same width and height, it will be scaled down to the closest
  * width/height and then cropped.
  *
  * To size an image to a specific width, set the width value needed and the height value to 0. 
  * This ensures the specified width is met, and the height is adjusted proportionally. The same
  * can be done by setting the height needed and the width to 0.
  *
  * @param $id int The id of image to get
  * @param $rotation int The degrees to rotate the image, can be null
  * @param $widthOrPercent int When by itself, represents percent to increase/decrease size.
  *      When used with the height param, represents the image width.
  * @param $height int The height to size the image.
  *
  * @return string The relative path from ROOT to the file, if it exists. Boolean false otherwise.
  */
 public function render($id, $rotation = null, $widthOrPercent = null, $height = null)
 {
     try {
         if ($image = Media::m('file')->find($id)) {
             $ext = pathinfo($image->name, PATHINFO_EXTENSION);
             $cachedFilename = str_replace('.' . $ext, sprintf('_%d.%s', $id . $rotation . $widthOrPercent . $height, $ext), $image->name);
             $cachedFullPath = ROOT . Media::getFilesPath() . Media::getCachePath() . $cachedFilename;
             if (!file_exists($cachedFullPath)) {
                 $origFullPath = ROOT . Media::getFilesPath() . $image->path . $image->name;
                 Media_Imager::open($origFullPath);
                 if (!is_null($widthOrPercent) && is_null($height)) {
                     Media_Imager::percent($widthOrPercent);
                 } elseif (!is_null($widthOrPercent) && !is_null($height)) {
                     $adaptive = $widthOrPercent == 0 || $height == 0 ? false : true;
                     Media_Imager::resize($widthOrPercent, $height, $adaptive);
                 }
                 if (!is_null($rotation) && $rotation > 0) {
                     Media_Imager::rotate($rotation);
                 }
                 Media_Imager::save($cachedFullPath);
             }
             return Media::getFilesPath() . Media::getCachePath() . $cachedFilename;
         }
     } catch (Exception $e) {
         Log::error('media', $e->getMessage());
     }
     return false;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:48,代码来源:media_image.php

示例3: getPath

 /**
  * Returns the relative path from ROOT to the file.
  */
 public function getPath($id)
 {
     if ($file = Media::m('file')->find($id)) {
         $path = Media::getFilesPath() . $file->path . $file->name;
         if (file_exists($path)) {
             return $path;
         }
     }
     return false;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:13,代码来源:media_file.php

示例4: download

 /**
  * Forces a download of the file based on the given id. If the file doesn't
  * exist, 404 is shown.
  */
 public static function download($id)
 {
     $file = Media::m('file')->find($id);
     if ($file) {
         $filePath = Media::getFilesPath() . $file->path . $file->name;
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . $file->name);
         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: ' . $file->size);
         ob_clean();
         flush();
         readfile($file_path);
         exit;
     }
     return ERROR_404;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:23,代码来源:file.php

示例5: _getNewNameAndPath

 /**
  * Gets a new, unused filename for the given filename and returns it with
  * the full path to the new filename.
  *
  * @param string $filename The original filename, no paths.
  *
  * @return An array, first element is the new filename, the second is the full path.
  */
 private static function _getNewNameAndPath($filename)
 {
     if (!($filesPath = Media::getFilesPath())) {
         self::$_error = 'Files directory doesn\'t exist or isn\'t writable.';
         return false;
     }
     if (!($mediaPath = Media::getMediaPath())) {
         self::$_error = 'Media directory doesn\'t exist or isn\'t writable.';
         return false;
     }
     $uploadPath = $filesPath . $mediaPath;
     $newFilename = self::_getAvailFilename($filename, $uploadPath);
     $fullPath = ROOT . $uploadPath . $newFilename;
     return array($newFilename, $fullPath);
 }
开发者ID:simudream,项目名称:caffeine,代码行数:23,代码来源:media_uploader.php


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