本文整理汇总了PHP中FileManager::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::getExtension方法的具体用法?PHP FileManager::getExtension怎么用?PHP FileManager::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::getExtension方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExtension
/**
* Get the file's extension.
* @return string
*/
function getExtension()
{
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
return strtoupper($fileManager->getExtension($this->getData('fileName')));
}
示例2: truncateFileName
/**
* Truncate a filename to fit in the specified length.
*/
function truncateFileName($fileName, $length = 127)
{
if (String::strlen($fileName) <= $length) {
return $fileName;
}
$ext = FileManager::getExtension($fileName);
$truncated = String::substr($fileName, 0, $length - 1 - String::strlen($ext)) . '.' . $ext;
return String::substr($truncated, 0, $length);
}
示例3: updateUserFileList
static function updateUserFileList($id = 0)
{
global $loginManager;
if (WEBSOCKET != 1 || empty($id) || !is_numeric($id)) {
$id = $loginManager->getId();
}
$basedir = dirname(dirname(__FILE__)) . '/data/user_' . $id . '/files';
$audio = null;
$video = null;
$images = null;
$directory = new RecursiveDirectoryIterator($basedir);
$objects = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
$extension = FileManager::getExtension($name);
if (!FileManager::isVisible($object)) {
continue;
}
if (in_array(strtoupper($extension), FileManager::EXTENSION_IMAGES)) {
$images[] = str_replace($basedir, '', $name);
} else {
if (in_array(strtoupper($extension), FileManager::EXTENSION_VIDEO)) {
$video[] = str_replace($basedir, '', $name);
} else {
if (in_array(strtoupper($extension), FileManager::EXTENSION_AUDIO)) {
$audio[] = str_replace($basedir, '', $name);
}
}
}
}
if (empty($images)) {
$images = array();
}
if (empty($audio)) {
$audio = array();
}
if (empty($video)) {
$video = array();
}
$datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/image.json', "w+");
fwrite($datei, json_encode($images));
fclose($datei);
$datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/video.json', "w+");
fwrite($datei, json_encode($video));
fclose($datei);
$datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/audio.json', "w+");
fwrite($datei, json_encode($audio));
fclose($datei);
}
示例4: import
/**
* Resize cover thumnails for all given press objects (categories, series and published monographs).
* @param $context Context
* @param $objectDao CategoriesDAO, SeriesDAO or PublishedMonographsDAO
* @param $coverThumbnailsMaxWidth int
* @param $coverThumbnailsMaxHeight int
* @param $basePath string Base path for the given object
*/
function _resizeCoverThumbnails($context, $objectDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, $basePath)
{
import('classes.file.SimpleMonographFileManager');
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$objects = $objectDao->getByPressId($context->getId());
while ($object = $objects->next()) {
if (is_a($object, 'PublishedMonograph')) {
$cover = $object->getCoverImage();
$simpleMonographFileManager = new SimpleMonographFileManager($context->getId(), $object->getId());
$basePath = $simpleMonographFileManager->getBasePath();
} else {
$cover = $object->getImage();
}
if ($cover) {
// delete old cover thumbnail
$fileManager->deleteFile($basePath . $cover['thumbnailName']);
// get settings necessary for the new thumbnail
$coverExtension = $fileManager->getExtension($cover['name']);
$xRatio = min(1, $coverThumbnailsMaxWidth / $cover['width']);
$yRatio = min(1, $coverThumbnailsMaxHeight / $cover['height']);
$ratio = min($xRatio, $yRatio);
$thumbnailWidth = round($ratio * $cover['width']);
$thumbnailHeight = round($ratio * $cover['height']);
// create a thumbnail image of the defined size
$thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
// generate the image of the original cover
switch ($coverExtension) {
case 'jpg':
$coverImage = imagecreatefromjpeg($basePath . $cover['name']);
break;
case 'png':
$coverImage = imagecreatefrompng($basePath . $cover['name']);
break;
case 'gif':
$coverImage = imagecreatefromgif($basePath . $cover['name']);
break;
default:
$coverImage = null;
// Suppress warn
}
assert($coverImage);
// copy the cover image to the thumbnail
imagecopyresampled($thumbnail, $coverImage, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $cover['width'], $cover['height']);
// create the thumbnail file
switch ($coverExtension) {
case 'jpg':
imagejpeg($thumbnail, $basePath . $cover['thumbnailName']);
break;
case 'png':
imagepng($thumbnail, $basePath . $cover['thumbnailName']);
break;
case 'gif':
imagegif($thumbnail, $basePath . $cover['thumbnailName']);
break;
}
imagedestroy($thumbnail);
if (is_a($object, 'PublishedMonograph')) {
$object->setCoverImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'catalogName' => $cover['catalogName'], 'catalogWidth' => $cover['v'], 'catalogHeight' => $cover['catalogHeight'], 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded']));
} else {
$object->setImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded']));
}
// Update category object to store new thumbnail information.
$objectDao->updateObject($object);
}
unset($object);
}
}
示例5: getFileExtension
/**
* Get extension of the file.
* @ return string
*/
function getFileExtension()
{
return FileManager::getExtension($this->getData('originalName'));
}