本文整理汇总了PHP中File::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getMimeType方法的具体用法?PHP File::getMimeType怎么用?PHP File::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::getMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
/**
* Runs the test.
*/
public function test()
{
$path = DIR_FILES . '/mail/logo.gif';
$name = 'logo.gif';
$mimeType = 'image/gif';
$attachment = new File($path, $name, $mimeType);
$this->assertEquals(file_get_contents($path), $attachment->getContent());
$this->assertEquals($name, $attachment->getName());
$this->assertEquals($mimeType, $attachment->getMimeType());
$this->assertEquals(\Jyxo\Mail\Email\Attachment::DISPOSITION_ATTACHMENT, $attachment->getDisposition());
$this->assertFalse($attachment->isInline());
$this->assertEquals('', $attachment->getCid());
$this->assertEquals('', $attachment->getEncoding());
}
示例2: fromRequest
function fromRequest()
{
$data = parent::fromRequest();
$fields = $this->meta['fields'];
if (array_key_exists('mime_type', $fields) && array_key_exists('from_db', $fields) && array_key_exists('content', $fields)) {
switch (true) {
case !empty($data['mime_type']):
break;
case !empty($data['content']['type']):
$data['mime_type'] = $data['content']['type'];
break;
}
if (!empty($data['content']['tmp_name'])) {
//Mime type first
if (empty($data['mime_type'])) {
$data['mime_type'] = File::getMimeType($data['content']['tmp_name'], $this->default_type);
}
$data['meta_info'] = $this->getMetaInfo(array($data['content']['tmp_name'], $data['content']['name']));
//Overwrite content with file contents
if ($data['from_db']) {
$data['content'] = file_get_contents($data['content']['tmp_name']);
} else {
$folder = self::checkUploadFolder($this->meta['table']);
if ($folder) {
//We add the timestamp to ensure that the name is unique
$destination = $folder . time() . '.' . basename($data['content']['name']);
if (move_uploaded_file($data['content']['tmp_name'], $destination)) {
$data['content'] = $destination;
} else {
Backend::addError('Could not upload file');
$data = false;
}
} else {
$data = false;
}
}
}
}
return $data;
}
示例3: getThumbPrevText
/**
* Make the text under the image to say what size preview
*
* @param $params Array parameters for thumbnail
* @param $sizeLinkBigImagePreview HTML for the current size
* @return string HTML output
*/
private function getThumbPrevText($params, $sizeLinkBigImagePreview)
{
if ($sizeLinkBigImagePreview) {
// Show a different message of preview is different format from original.
$previewTypeDiffers = false;
$origExt = $thumbExt = $this->displayImg->getExtension();
if ($this->displayImg->getHandler()) {
$origMime = $this->displayImg->getMimeType();
$typeParams = $params;
$this->displayImg->getHandler()->normaliseParams($this->displayImg, $typeParams);
list($thumbExt, $thumbMime) = $this->displayImg->getHandler()->getThumbType($origExt, $origMime, $typeParams);
if ($thumbMime !== $origMime) {
$previewTypeDiffers = true;
}
}
if ($previewTypeDiffers) {
return $this->getContext()->msg('show-big-image-preview-differ')->rawParams($sizeLinkBigImagePreview)->params(strtoupper($origExt))->params(strtoupper($thumbExt))->parse();
} else {
return $this->getContext()->msg('show-big-image-preview')->rawParams($sizeLinkBigImagePreview)->parse();
}
} else {
return '';
}
}
示例4: isImageAreaOkForThumbnaling
/**
* Check if the file is smaller than the maximum image area for thumbnailing.
*
* Runs the 'BitmapHandlerCheckImageArea' hook.
*
* @param File $file
* @param array $params
* @return bool
* @since 1.25
*/
public function isImageAreaOkForThumbnaling($file, &$params)
{
global $wgMaxImageArea;
# For historical reasons, hook starts with BitmapHandler
$checkImageAreaHookResult = null;
Hooks::run('BitmapHandlerCheckImageArea', array($file, &$params, &$checkImageAreaHookResult));
if (!is_null($checkImageAreaHookResult)) {
// was set by hook, so return that value
return (bool) $checkImageAreaHookResult;
}
$srcWidth = $file->getWidth($params['page']);
$srcHeight = $file->getHeight($params['page']);
if ($srcWidth * $srcHeight > $wgMaxImageArea && !($file->getMimeType() == 'image/jpeg' && $this->getScalerType(false, false) == 'im')) {
# Only ImageMagick can efficiently downsize jpg images without loading
# the entire file in memory
return false;
}
return true;
}
示例5: writeViewData
/**
* writeViewData
* @param File $objFile
* @author Cornelius Hansjakob <cha@massiveart.at>
* @version 1.0
*/
private function writeViewData(File &$objFile)
{
$this->core->logger->debug('media->controllers->UploadController->writeViewData()');
$this->view->assign('fileId', $objFile->getId());
$this->view->assign('fileFileId', $objFile->getFileId());
$this->view->assign('fileExtension', $objFile->getExtension());
$this->view->assign('fileTitle', $objFile->getTitle());
$this->view->assign('mimeType', $objFile->getMimeType());
$this->view->assign('strDefaultDescription', 'Beschreibung hinzufügen...');
// TODO : guiTexts
$this->view->assign('languageId', 1);
// TODO : language
}
示例6: getGeneralLongDesc
/**
* Used instead of getShortDesc if there is no handler registered for file.
*
* @param File $file
* @return string
*/
static function getGeneralLongDesc($file)
{
global $wgLang;
return wfMessage('file-info', $wgLang->formatSize($file->getSize()), $file->getMimeType())->parse();
}
示例7: getLongDesc
/**
* @param File $file
* @return string
*/
function getLongDesc($file)
{
global $wgLang;
$pages = $file->pageCount();
$size = htmlspecialchars($wgLang->formatSize($file->getSize()));
if ($pages === false || $pages <= 1) {
$msg = wfMessage('file-info-size')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->parse();
} else {
$msg = wfMessage('file-info-size-pages')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->numParams($pages)->parse();
}
return $msg;
}
示例8: createFromFileByMime
/**
* @param string $path
* @return resource GD image
* @throws Exception
*/
private static function createFromFileByMime($path)
{
$mime = File::getMimeType($path);
switch ($mime) {
case 'image/jpeg':
$img = imagecreatefromjpeg($path);
break;
case 'image/gif':
$img = imagecreatefromgif($path);
break;
case 'image/png':
$img = imagecreatefrompng($path);
break;
default:
throw new Exception('can`t create thumbnail: unknown image type');
}
if (!$img) {
throw new Exception('can`t create thumbnail: can`t create image handle from file ' . $path);
}
return $img;
}
示例9: checkExtensionCompatibility
/**
* Checks if file extensions are compatible
*
* @param $old File Old file
* @param $new string New name
*
* @return bool|null
*/
static function checkExtensionCompatibility(File $old, $new)
{
$oldMime = $old->getMimeType();
$n = strrpos($new, '.');
$newExt = self::normalizeExtension($n ? substr($new, $n + 1) : '');
$mimeMagic = MimeMagic::singleton();
/** Wikia change start, author Jacek Jursza, bug id: 31194 - not able to rename video files **/
$result = $mimeMagic->isMatchingExtension($newExt, $oldMime);
wfRunHooks('File::checkExtensionCompatibilityResult', array(&$result, &$old, &$oldMime, &$newExt));
return $result;
/** Wikia change end **/
}
示例10: getVipsHandler
/**
* Return the appropriate im_XXX2vips handler for this file
* @param File $file
* @return mixed String or false
*/
public static function getVipsHandler( $file ) {
list( $major, $minor ) = File::splitMime( $file->getMimeType() );
if ( $major == 'image' && in_array( $minor, array( 'jpeg', 'png', 'tiff' ) ) ) {
return "im_{$minor}2vips";
} else {
return false;
}
}
示例11: setFile
public function setFile(File $toSave)
{
$permissionEngine = PermissionEngine::getInstance();
if (!$permissionEngine->currentUserCanDo('uploadFile')) {
return false;
}
$database = Database::getInstance();
if (!$database->isConnected()) {
return false;
}
$validator = new checkIfKnownMimeType();
if (!$validator->validate($toSave->getMimeType())) {
return false;
}
if (!is_readable($toSave->getLocation())) {
return false;
}
$id = $database->escapeString($toSave->getID());
$dateUploaded = $database->escapeString($toSave->getUploadedDate()->format('Y-m-d H:i:s'));
$title = $database->escapeString(strip_tags($toSave->getTitle()));
$mimeType = $database->escapeString($toSave->getMimeType());
$size = $database->escapeString($toSave->getSize());
$location = $database->escapeString($toSave->getLocation());
$nodeID = $database->escapeString($toSave->getNodeID());
$uploader = $database->escapeString($toSave->getUploaderID());
$folder = $database->escapeString($toSave->getFolderID());
$result = $database->updateTable('file', "uploaded='{$dateUploaded}', title='{$title}', mimeType='{$mimeType}', size={$size}, location='{$location}', nodeID={$nodeID}, uploader={$uploader}, folderID={$folder}", "fileID='{$id}'");
if ($result === false) {
return false;
}
return true;
}
示例12: getGeneralLongDesc
/**
* Used instead of getLongDesc if there is no handler registered for file.
*
* @param File $file
* @return string
*/
static function getGeneralLongDesc($file)
{
return wfMessage('file-info')->sizeParams($file->getSize())->params($file->getMimeType())->parse();
}
示例13: checkExtensionCompatibility
/**
* Checks if file extensions are compatible
*
* @param $old File Old file
* @param string $new New name
*
* @return bool|null
*/
static function checkExtensionCompatibility(File $old, $new)
{
$oldMime = $old->getMimeType();
$n = strrpos($new, '.');
$newExt = self::normalizeExtension($n ? substr($new, $n + 1) : '');
$mimeMagic = MimeMagic::singleton();
return $mimeMagic->isMatchingExtension($newExt, $oldMime);
}
示例14: afterInsertFile
/**
* Try to post new file to Geoserver.
*
* @param File $file The file.
*
* @return void.
*/
public function afterInsertFile($file)
{
// Is the image a tiff?
if ($file->getMimeType() == 'image/tiff') {
// Get the active server.
$server = $this->serversTable->getActiveServer();
// Throw file at Geoserver.
if ($server && _putFileToGeoserver($file, $server)) {
// Get parent item and WMS.
$item = $file->getItem();
$wms = $this->servicesTable->findByItem($item);
// If no WMS exists, create one for the file that
// was just uploaded to Geoserver.
if (!$wms) {
$this->servicesTable->createFromFileAndServer($file, $server);
} else {
if ($wms->address == $server->getWmsAddress()) {
// If a WMS already exists and the address is the
// same as the address of the active server, append
// the new layer to the active layers list.
$wms->layers .= ',' . nlwms_layerName($server, $file);
$wms->save();
}
}
}
}
}
示例15: getLegacyUrl
/**
* @param File $img
* @param $width
* @param $height
* @return String
*/
private function getLegacyUrl($img, $width, $height)
{
$issvg = false;
$mime = strtolower($img->getMimeType());
if ($mime == 'image/svg+xml' || $mime == 'image/svg') {
$issvg = true;
}
$sPrefix = '';
if (WikiaFileHelper::isVideoFile($img)) {
// videos has different thumbnail markup
$sPrefix = 'v,000000,';
}
$url = wfReplaceImageServer($img->getThumbUrl($sPrefix . $this->getCut($width, $height) . "-" . $img->getName() . ($issvg ? ".png" : "")));
wfProfileOut(__METHOD__);
return $url;
}