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


PHP Media::m方法代码示例

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


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

示例1: 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

示例2: render

 /**
  * TODO Comments.
  */
 public static function render($id, $rotation = null, $widthOrPercent = null, $height = null)
 {
     $image = Media::m('file')->find($id);
     $path = Media::image()->render($id, $rotation, $widthOrPercent, $height);
     header('Content-Type: ' . $image->mime_type);
     readfile(ROOT . $path);
     die;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:11,代码来源: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: embed

 /**
  * TODO Comments.
  */
 public function embed($id, $width = 560, $height = 345)
 {
     if ($video = Media::m('url')->find($id)) {
         $data = unserialize($video->data);
         if (stristr($video->url, 'youtube')) {
             return sprintf('<iframe width="%d" height="%d" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>', $width, $height, $data['id']);
         }
         if (stristr($video->url, 'vimeo')) {
             return sprintf('<iframe src="http://player.vimeo.com/video/%s?title=0&amp;byline=0&amp;portrait=0" width="%d" height="%d" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>', $data['id'], $width, $height);
         }
     }
 }
开发者ID:simudream,项目名称:caffeine,代码行数:15,代码来源:media_video.php

示例5: delete

 /**
  * Deletes the file associated with the given id from the system.
  *
  * @param $id int The id of the file to delete.
  * @return boolean
  */
 public static function delete($id)
 {
     if ($file = Media::m('file')->find($id)) {
         $filePath = ROOT . self::getFilesPath() . $file->path . $file->name;
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         self::clearCache($file);
         if (Media::m('file')->delete($id)) {
             return true;
         }
     }
     return false;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:20,代码来源:media.php

示例6: 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

示例7: saveFromUrl

 /**
  * Saves a file from a url.
  *
  * @param string $url The full url for the file to save.
  * @param string $type The file type to store in the db (file, image, video)
  *
  * @return Returns the media id if created successfully, boolean false otherwise.
  */
 public static function saveFromUrl($url, $type)
 {
     if (!($nameAndPath = self::_getNewNameAndPath(basename($url)))) {
         return false;
     }
     list($newFilename, $fullPath) = $nameAndPath;
     if ($urlContent = file_get_contents($url)) {
         if (file_put_contents($fullPath, $urlContent)) {
             $id = Media::m('file')->insert(array('name' => $newFilename, 'path' => Media::getMediaPath(), 'size' => filesize($fullPath), 'mime_type' => self::_determineMimeType($fullPath), 'file_type' => $type));
             return $id;
         } else {
             self::$_error = 'Unable to save ' . $type . ' from URL.';
         }
     } else {
         self::$_error = 'Unable to read file contents from URL.';
         Dev::debug('media', 'ERROR: Cant save from url: ' . $url);
     }
     return false;
 }
开发者ID:simudream,项目名称:caffeine,代码行数:27,代码来源:media_uploader.php


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