本文整理汇总了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;
}
示例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);
}
示例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}";
}