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


PHP Files::getFileFromKey方法代码示例

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


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

示例1: viewAction

 public function viewAction()
 {
     // We view a file, so we should disable layout
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $key = $this->_getParam('key');
     $size = $this->_getParam('size');
     $inline = $this->_getParam('inline');
     if (strpos($key, '.')) {
         $key = substr($key, 0, strpos($key, '.'));
     }
     $files = new Files();
     if (!($file = $files->getFileFromKey($key))) {
         throw new Stuffpress_Exception("No such file for key {$key}");
     }
     if ($size == 'thumbnail') {
         $folder = '/thumbnails/';
     } else {
         if ($size == 'small') {
             $folder = '/small/';
         } else {
             if ($size == 'medium') {
                 $folder = '/medium/';
             } else {
                 if ($size == 'large') {
                     $folder = '/large/';
                 } else {
                     $folder = '/';
                 }
             }
         }
     }
     $root = Zend_Registry::get("root");
     $config = Zend_Registry::get("configuration");
     if (isset($config) && isset($config->path->upload)) {
         $upload = $config->path->upload;
     } else {
         $upload = $root . "/upload/";
     }
     $path = $upload . "/{$folder}{$file->key}";
     if ($folder != '/' && !file_exists($path)) {
         $path = $upload . "/{$file->key}";
     }
     // Dump the file
     if (!$inline) {
         header("Content-Disposition: attachment; filename=\"{$file->name}\"");
     }
     header("Content-type: {$file->type}");
     header('Content-Length: ' . filesize($path));
     /*$this->getResponse()->setHeader('Expires', '', true);
        $this->getResponse()->setHeader('Cache-Control', 'public', true);
      	$this->getResponse()->setHeader('Cache-Control', 'max-age=3800');
        $this->getResponse()->setHeader('Pragma', '', true);*/
     // We turn off output buffering to avoid memory issues
     // when dumping the file
     ob_end_flush();
     readfile($path);
     // Die to make sure that we don't screw up the file
     die;
 }
开发者ID:segphault,项目名称:storytlr,代码行数:60,代码来源:FileController.php

示例2: setcoverAction

 public function setcoverAction()
 {
     // Get, check and setup the parameters
     $story_id = $this->getRequest()->getParam("story");
     $source_id = $this->getRequest()->getParam("source");
     $item_id = $this->getRequest()->getParam("item");
     //Verify if the requested story exist
     $stories = new Stories();
     if (!($story = $stories->getStory($story_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $story->user_id) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested source exist
     $sources = new Sources();
     if (!($source = $sources->getSource($source_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $source['user_id']) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested item exist
     $data = new Data();
     if (!($item = $data->getItem($source_id, $item_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Do we have a url ?
     if (!($url = $item->getImageUrl(ImageItem::SIZE_MEDIUM))) {
         return $this->_helper->json->sendJson(false);
     }
     // Get the old image and delete it
     $files = new Files();
     if ($file = $files->getFileFromKey($story->thumbnail)) {
         $files->deleteFile($file->key);
     }
     // Ok, we can set the image
     $this->setKeyImage($story_id, $url);
     return $this->_helper->json->sendJson(true);
 }
开发者ID:kreativmind,项目名称:storytlr,代码行数:42,代码来源:StoryController.php

示例3: getAudioUrl

 public function getAudioUrl($format = 'mp3')
 {
     if ($this->getType() != SourceItem::AUDIO_TYPE) {
         return false;
     }
     // If we have a URL, eturn directly
     if (strlen($this->_data['url']) > 0) {
         return $this->_data['url'];
     }
     // Get the file key
     $key = $this->_data['file'];
     // Get the file
     $files = new Files();
     $file = $files->getFileFromKey($key);
     $name = urlencode($file['name']);
     // Get the root url
     $host = trim(Zend_Registry::get("host"), '/');
     // Return the final URL
     return "http://{$host}/file/view/key/{$key}/{$name}";
 }
开发者ID:kreativmind,项目名称:storytlr,代码行数:20,代码来源:StuffpressItem.php


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