本文整理汇总了PHP中FileHelper::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::getMimeType方法的具体用法?PHP FileHelper::getMimeType怎么用?PHP FileHelper::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelper
的用法示例。
在下文中一共展示了FileHelper::getMimeType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getWidgetIconSvg
/**
* Returns a widget type’s SVG icon.
*
* @param IWidget $widgetType
*
* @return string
*/
private function _getWidgetIconSvg(IWidget $widgetType)
{
$iconPath = $widgetType->getIconPath();
if ($iconPath && IOHelper::fileExists($iconPath) && FileHelper::getMimeType($iconPath) == 'image/svg+xml') {
return IOHelper::getFileContents($iconPath);
}
return craft()->templates->render('_includes/defaulticon.svg', array('label' => $widgetType->getName()));
}
示例2: getMimeType
/**
* If the path points to a real file, we call {@link FileHelper::getMimeType()}, otherwise
* {@link FileHelper::getMimeTypeByExtension()}
*
* @param string $path The path to test.
*
* @return string The mime type.
*/
public static function getMimeType($path)
{
if (@file_exists($path)) {
return FileHelper::getMimeType($path);
} else {
return FileHelper::getMimeTypeByExtension($path);
}
}
示例3: loadImage
/**
* Loads an image from a file system path.
*
* @param string $path
*
* @throws Exception
* @return Image
*/
public function loadImage($path)
{
if (!IOHelper::fileExists($path)) {
throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
}
if (!craft()->images->checkMemoryForImage($path)) {
throw new Exception(Craft::t("Not enough memory available to perform this image operation."));
}
// Make sure the image says it's an image
$mimeType = FileHelper::getMimeType($path, null, false);
if ($mimeType !== null && strncmp($mimeType, 'image/', 6) !== 0) {
throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
}
try {
$this->_image = $this->_instance->open($path);
} catch (\Exception $exception) {
throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
}
// If we're using Imagick _and_ one that supports it, convert CMYK to RGB, save and re-open.
if (!craft()->images->isGd() && $this->_image->getImagick()->getImageColorspace() == \Imagick::COLORSPACE_CMYK && method_exists($this->_image->getImagick(), 'transformimagecolorspace')) {
$this->_image->getImagick()->transformimagecolorspace(\Imagick::COLORSPACE_SRGB);
$this->_image->save();
return craft()->images->loadImage($path);
}
$this->_imageSourcePath = $path;
$this->_extension = IOHelper::getExtension($path);
if ($this->_extension == 'gif') {
if (!craft()->images->isGd() && $this->_image->layers()) {
$this->_isAnimatedGif = true;
}
}
$this->_resizeHeight = $this->getHeight();
$this->_resizeWidth = $this->getWidth();
return $this;
}
示例4: testDetectsCorrectMimeTypeUsingMagicNumbersAndFallingBackToExtensionLookupForSwf
public function testDetectsCorrectMimeTypeUsingMagicNumbersAndFallingBackToExtensionLookupForSwf()
{
$pathToFile = dirname(__FILE__) . '/../../../../../resources/test.swf';
$this->assertEquals('application/x-shockwave-flash', FileHelper::getMimeType($pathToFile));
}