本文整理汇总了PHP中MIME_Type类的典型用法代码示例。如果您正苦于以下问题:PHP MIME_Type类的具体用法?PHP MIME_Type怎么用?PHP MIME_Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MIME_Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoDetect
public static function autoDetect($file)
{
$mt = new MIME_Type();
$mt->magicFile = static::getMagicFile();
$mt->useMimeContentType = false;
//fixme: finfo doesn't give the correct results
// only fixed in PHP 5.4.4
$mt->useFileCmd = true;
$mt->useFinfo = false;
$mt->useExtension = false;
$type = $mt->autoDetect($file);
if ($type !== 'text/plain') {
return $type;
}
$type = MIME_Type::autoDetect($file);
return $type;
}
示例2: parse
/**
* Parse a MIME type parameter and set object fields
*
* @param string $param MIME type parameter to parse
* @return void
*/
function parse($param)
{
$comment = '';
$param = MIME_Type::stripComments($param, $comment);
$this->name = $this->getAttribute($param);
$this->value = $this->getValue($param);
$this->comment = $comment;
}
示例3: mime_type_of_file
function mime_type_of_file($path)
{
$result = FALSE;
if (class_exists('MIME_Type')) {
$result = MIME_Type::autoDetect($path);
if (PEAR::isError($result)) {
$result = FALSE;
}
}
return $result;
}
示例4: getExtension
/**
* Return default MIME-type for the specified extension.
*
* @param string $type MIME-type
*
* @return string A file extension without leading period.
*/
function getExtension($type)
{
include_once 'MIME/Type.php';
// Strip parameters and comments.
$type = MIME_Type::getMedia($type) . '/' . MIME_Type::getSubType($type);
$extension = array_search($type, $this->extensionToType);
if ($extension === false) {
return PEAR::raiseError("Sorry, couldn't determine extension.");
}
return $extension;
}
示例5: isTrue
/**
* @see File_Archive_Predicate::isTrue()
*/
function isTrue(&$source)
{
$sourceMIME = $source->getMIME();
foreach ($this->mimes as $mime) {
if (MIME_Type::isWildcard($mime)) {
$result = MIME_Type::wildcardMatch($mime, $sourceMIME);
} else {
$result = $mime == $sourceMIME;
}
if ($result !== false) {
return $result;
}
}
return false;
}
示例6: autoDetectMIMETypeFromFile
/**
* Returns mime type from the actual file using a detection library
* @access protected
* @return string or boolean
*/
protected function autoDetectMIMETypeFromFile($filename)
{
$settings = $this->defaults['mime_type'];
$support_libraries = array('fileinfo', 'mime_type', 'gd_mime_type');
if (false === $settings['auto_detect']) {
return false;
}
if (in_array(strtolower($settings['library']), $support_libraries) && '' !== $filename) {
if ('gd_mime_type' === strtolower($settings['library'])) {
if (!extension_loaded('gd')) {
throw new Exception('GD not enabled. Cannot detect mime type using GD.');
}
$imgData = GetImageSize($filename);
if (isset($imgData['mime'])) {
return $imgData['mime'];
} else {
return false;
}
}
if ('fileinfo' === strtolower($settings["library"])) {
if (function_exists('finfo_file')) {
// Support for PHP 5.3+
if (defined(FILEINFO_MIME_TYPE)) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
} else {
$finfo = finfo_open(FILEINFO_MIME);
}
return finfo_file($finfo, $filename);
}
}
if ('mime_type' === strtolower($settings["library"])) {
// Supressing warning as PEAR is not strict compliant
@(require_once 'MIME/Type.php');
if (method_exists('\\MIME_Type', 'autoDetect')) {
return @\MIME_Type::autoDetect($filename);
}
}
}
return false;
}
示例7: sendEMail
function sendEMail($par, $file = false)
{
$recipients = $par['empfaenger'];
$message_array = $par['message'];
$from = 'Develop.Entertainment@gfk.com';
$backend = 'smtp';
$subject = $message_array['subject'];
$body_txt = $message_array['body_txt'];
$crlf = "\n";
$params = array('host' => '10.149.43.10', 'port' => 25, 'auth' => false, 'username' => false, 'password' => false, 'localhost' => 'localhost', 'timeout' => null, 'debug' => false);
foreach ($recipients as $recipient) {
$headers = array('From' => $from, 'To' => $recipient, 'Subject' => $subject);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($body_txt);
if (is_file($file)) {
$ctype = MIME_Type::autoDetect($file);
$mime->addAttachment($file, $ctype);
}
$body = $mime->get();
$hdrs = $mime->headers($headers);
$mail =& Mail::factory($backend, $params);
$mail->send($recipient, $hdrs, $body);
}
}
示例8: testComments
public function testComments()
{
$type = new MIME_Type('(UTF-8 Plain Text) text / plain ; charset = utf-8');
$this->assertEquals('text/plain; charset="utf-8"', $type->get());
$type = new MIME_Type('text (Text) / plain ; charset = utf-8');
$this->assertEquals('text/plain; charset="utf-8"', $type->get());
$type = new MIME_Type('text / (Plain) plain ; charset = utf-8');
$this->assertEquals('text/plain; charset="utf-8"', $type->get());
$type = new MIME_Type('text / plain (Plain Text) ; charset = utf-8');
$this->assertEquals('text/plain; charset="utf-8"', $type->get());
$type = new MIME_Type('text / plain ; (Charset=utf-8) charset = utf-8');
$this->assertEquals('text/plain; charset="utf-8" (Charset=utf-8)', $type->get());
$type = new MIME_Type('text / plain ; charset (Charset) = utf-8');
$this->assertEquals('text/plain; charset="utf-8" (Charset)', $type->get());
$type = new MIME_Type('text / plain ; charset = (UTF8) utf-8');
$this->assertEquals('text/plain; charset="utf-8" (UTF8)', $type->get());
$type = new MIME_Type('text / plain ; charset = utf-8 (UTF-8 Plain Text)');
$this->assertEquals('text/plain; charset="utf-8" (UTF-8 Plain Text)', $type->get());
$type = new MIME_Type('application/x-foobar;description="bbgh(kdur"');
$this->assertEquals('application/x-foobar; description="bbgh(kdur"', $type->get());
$type = new MIME_Type('application/x-foobar;description="a \\"quoted string\\""');
$this->assertEquals('application/x-foobar; description="a \\"quoted string\\""', $type->get());
}
示例9: ini_set
<?php
ini_set('include_path', ini_get('include_path') . ':/home/dvaqpvvw/php/:');
ini_set('include_path', ini_get('include_path') . ':/home/dvaqpvvw/php/MIME/:');
ini_set('include_path', ini_get('include_path') . ':/home/dvaqpvvw/php/PEAR/:');
require_once '/home/dvaqpvvw/php/MIME/Type.php';
$filename = urldecode($_REQUEST['filename']);
$shortFilename = urldecode($_REQUEST['shortFilename']);
$mimeType = MIME_Type::autoDetect($filename);
header("Content-disposition: attachment; filename=" . $shortFilename);
header("Content-type:" . $mimeType);
readfile($filename);
function getMimeType()
{
}
示例10: detect
public function detect($filepath)
{
return MIME_Type::autoDetect($filepath);
}
示例11: autoDetect
/**
* Autodetect a file's MIME-type
*
* This function may be called staticly.
*
* @param string $file Path to the file to get the type of
* @param string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser
* @param bool $params Append MIME parameters if true
* @return string $file's MIME-type on success, false boolean otherwise
* @since 1.0.0beta1
* @static
*/
function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false)
{
if (function_exists('mime_content_type')) {
$type = mime_content_type($file);
if ($type == "application/octet-stream" || $type == "application/unknown") {
if (!empty($custom_mime)) {
$type = $custom_mime;
} elseif (!empty($custom_ext)) {
$type = MIME_Helper::convertExtensionToMime($custom_ext);
}
}
} elseif (!empty($custom_mime)) {
$type = $custom_mime;
} else {
$type = MIME_Type::_fileAutoDetect($file);
}
// _fileAutoDetect() may have returned an error.
if ($type === false) {
return $type;
}
//return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function.");
if (!MIME_Helper::convertMimeToExtension($type)) {
$type = MIME_Helper::convertExtensionToMime($custom_mime);
}
// flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype)
if ($custom_ext == "flv") {
$type = "video/x-flv";
}
// Don't return an empty string
if (!$type || !strlen($type)) {
//return PEAR::raiseError("Sorry, couldn't determine file type.");
return false;
}
// Strip parameters if present & requested
if (MIME_Type::hasParameters($type) && !$params) {
$type = MIME_Type::stripParameters($type);
}
return $type;
}
示例12: getExtension
/**
* ファイル拡張子を取得する
* ・ファイル情報からファイル拡張子を取得する
* (自動判定するファイル拡張子:jpg, gif, png, zip, xls, pdf, doc, ppt, lzh)
* ・ファイルタイプが自動判定されなかった場合は、ファイル名から拡張子を取り出す
* ※ファイル保存されているファイルの拡張子を取得する場合に使用する
* @access public
* @param string $path ファイルパス
* @return string ファイル拡張子
*/
public function getExtension($path)
{
// パラメータチェック
if (empty($path)) {
throw new ApplicationException('Invalid parameter! $path=' . $path);
}
$realpath = realpath($path);
if ($path === false) {
throw new ApplicationException('Invalid parameter! $path=' . $path);
} elseif (strncmp($path, $realpath, strlen($realpath)) !== 0) {
throw new ApplicationException('Invalid parameter! $path=' . $path);
}
// 拡張子自動判定
$mime_type = MIME_Type::autoDetect($path);
$ext = $this->getExtentionEx($mime_type, $path);
$temp = array();
if (empty($ext)) {
// ファイル名から拡張子を取得する
preg_match("/^(.*)\\.(.*)\$/i", $path, $temp);
$ext = $temp[2];
}
return $ext;
}
示例13: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) {
return;
}
if ($this->supported && $this->enabled) {
include_once "simple_html_dom.php";
$body = $this->getResponse()->getBody();
$html = str_get_html($body);
if ($html) {
$images = $html->find("img");
foreach ($images as $image) {
$source = $image->src;
$path = null;
if (strpos($source, "http") === false) {
// check asset folder
if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
$path = PIMCORE_ASSET_DIRECTORY . $source;
} else {
if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
$path = PIMCORE_DOCUMENT_ROOT . $source;
}
}
if (is_file($path)) {
if (@filesize($path) < 20000) {
// only files < 20k because of IE8, 20000 because it's better to be a little bit under the limit
try {
$mimetype = MIME_Type::autoDetect($path);
if (is_string($mimetype)) {
$image->src = 'data:' . $mimetype . ';base64,' . base64_encode(file_get_contents($path));
}
} catch (Exception $e) {
}
}
}
}
}
$body = $html->save();
$this->getResponse()->setBody($body);
}
}
}
示例14: handle
/**
* Handle input, produce output
*
* @param array $args $_REQUEST contents
*
* @return void
*/
function handle($args)
{
// undo headers set by PHP sessions
$sec = session_cache_expire() * 60;
header('Expires: ' . date(DATE_RFC1123, time() + $sec));
header('Cache-Control: max-age=' . $sec);
parent::handle($args);
$path = $this->path;
header('Content-Type: ' . MIME_Type::autoDetect($path));
if (common_config('site', 'use_x_sendfile')) {
header('X-Sendfile: ' . $path);
} else {
header('Content-Length: ' . filesize($path));
readfile($path);
}
}
示例15: detectFormat
/**
* Detects the GeSHi language format of a file.
* It first detects the MIME type of the file and uses
* $typeToFormat to map that to GeSHi language formats.
*
* @param string $filename Full or relative path of the file to detect
*
* @return string GeSHi language format (e.g. 'php')
*/
protected function detectFormat($filename)
{
require_once 'MIME/Type.php';
$type = MIME_Type::autoDetect($filename);
if (!isset(self::$typeToFormat[$type])) {
throw new Exception('No idea which format this is: ' . $type);
}
return self::$typeToFormat[$type];
}