• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP MIME_Type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中MIME_Type的典型用法代码示例。如果您正苦于以下问题:PHP MIME_Type类的具体用法?PHP MIME_Type怎么用?PHP MIME_Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MIME_Type类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:stof,项目名称:MIME_Type_PlainDetect,代码行数:17,代码来源:PlainDetect.php


示例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;
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:14,代码来源:Parameter.php


示例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;
}
开发者ID:ronniebrito,项目名称:moodle_moviemasher,代码行数:11,代码来源:mimeutils.php


示例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;
 }
开发者ID:Dulciane,项目名称:jaws,代码行数:18,代码来源:Extension.php


示例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;
 }
开发者ID:ookwudili,项目名称:chisimba,代码行数:18,代码来源:MIME.php


示例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;
 }
开发者ID:hgabka,项目名称:imagerepo-bundle,代码行数:45,代码来源:ImageCreator.php


示例7: sendEMail

function sendEMail($par, $file = false)
{
    $recipients = $par['empfaenger'];
    $message_array = $par['message'];
    $from = '[email protected]';
    $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);
    }
}
开发者ID:MusicalAPP,项目名称:gfk-api-spotify-itunes,代码行数:24,代码来源:test.php


示例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());
 }
开发者ID:Bobsel,项目名称:gn-tic,代码行数:23,代码来源:TypeTest.php


示例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()
{
}
开发者ID:ctwoolsey,项目名称:stlbproWebsite_git,代码行数:15,代码来源:downloadGenericFile.php


示例10: detect

 public function detect($filepath)
 {
     return MIME_Type::autoDetect($filepath);
 }
开发者ID:haswalt,项目名称:Ferret,代码行数:4,代码来源:MIMEType.php


示例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;
 }
开发者ID:BGCX261,项目名称:zoom-gallery-svn-to-git,代码行数:51,代码来源:mime.class.php


示例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;
 }
开发者ID:nkawa,项目名称:acs-git-test,代码行数:33,代码来源:BaseAction.class.php


示例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);
         }
     }
 }
开发者ID:shanky0110,项目名称:pimcore-custom,代码行数:42,代码来源:ImageDataUri.php


示例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);
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:23,代码来源:getfile.php


示例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];
 }
开发者ID:rockylo,项目名称:geshi-1.1,代码行数:18,代码来源:geshi-cli.php


示例16: MIME_Type

<?php

/**
 * Demonstrates how to use a custom magic database.
 * The detected MIME type should be text/x-custom-mimetype
 */
require_once 'MIME/Type.php';
$mt = new MIME_Type();
$mt->magicFile = dirname(__FILE__) . '/custom-magic.magic';
$type = $mt->autoDetect(dirname(__FILE__) . '/custom-magic.php');
echo 'Type:    ' . $type . "\n";
echo 'Media:   ' . $mt->media . "\n";
echo 'Subtype: ' . $mt->subType . "\n";
开发者ID:pear,项目名称:mime_type,代码行数:13,代码来源:custom-magic.php


示例17: getUploadedFileType

 static function getUploadedFileType($f)
 {
     require_once 'MIME/Type.php';
     $cmd =& PEAR::getStaticProperty('MIME_Type', 'fileCmd');
     $cmd = common_config('attachments', 'filecommand');
     $filetype = null;
     if (is_string($f)) {
         // assuming a filename
         $filetype = MIME_Type::autoDetect($f);
     } else {
         // assuming a filehandle
         $stream = stream_get_meta_data($f);
         $filetype = MIME_Type::autoDetect($stream['uri']);
     }
     if (common_config('attachments', 'supported') === true || in_array($filetype, common_config('attachments', 'supported'))) {
         return $filetype;
     }
     $media = MIME_Type::getMedia($filetype);
     if ('application' !== $media) {
         $hint = sprintf(_(' Try using another %s format.'), $media);
     } else {
         $hint = '';
     }
     throw new ClientException(sprintf(_('%s is not a supported file type on this server.'), $filetype) . $hint);
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:25,代码来源:mediafile.php


示例18: test__callStaticUnknownMethod

 /**
  * @expectedException PHPUnit_Framework_Error
  * @expectedExceptionMessage Call to undefined method MIME_TYPE::doesNotExist()
  */
 public function test__callStaticUnknownMethod()
 {
     MIME_Type::doesNotExist();
 }
开发者ID:pear,项目名称:mime_type,代码行数:8,代码来源:TypeTest.php


示例19: read_mime

/**
 *	read a file's mimetype
 *
 *	first tries the PHP internal mime_content_type,
 * then falls back to PEAR library, the to unix file
 * to detect mimetype.
 *
 *	@access		public
 *	@param 		string	$file
 * @param		string	&$mime
 *	@return		bool
 *
 */
function read_mime($file, &$mime, $fallback_extension)
{
    global $file_binary, $ext_to_mime;
    $mime = '';
    if (function_exists('mime_content_type')) {
        $mime = @mime_content_type($file);
    }
    if ($mime != '') {
        return true;
    }
    if (function_exists('MIME_TYPE::autoDetect')) {
        $mime = @MIME_Type::autoDetect($file);
    }
    if ($mime != '') {
        return true;
    }
    unset($result);
    $cmd = $file_binary . " -b -i \"" . $file . "\"";
    @exec($cmd, $result);
    if (isset($result[0])) {
        if (preg_match("/^[a-zA-Z0-9-]+\\/[a-zA-Z0-9-]+\$/", trim($result[0]))) {
            $mime = trim($result[0]);
        }
    }
    if ($mime != '') {
        return true;
    } else {
        if ($fallback_extension) {
            if (key_exists($fallback_extension, $ext_to_mime)) {
                $mime = @$ext_to_mime[$fallback_extension];
            }
        }
    }
    if ($mime != '') {
        return true;
    } else {
        return false;
    }
}
开发者ID:BackupTheBerlios,项目名称:dilps,代码行数:52,代码来源:tools.inc.php


示例20: update

 /**
  * @return void
  */
 protected function update()
 {
     if (!$this->getFilename() && $this->getId() != 1) {
         $this->delete();
         throw new Exception("Asset requires filename, asset with id " . $this->getId() . " deleted");
     }
     // set date
     $this->setModificationDate(time());
     // save data
     $conf = Pimcore_Config::getSystemConfig();
     // create foldertree
     $destinationPath = $this->getFileSystemPath();
     if (!is_dir(dirname($destinationPath))) {
         mkdir(dirname($destinationPath), self::$chmod, true);
     }
     if ($this->_oldPath) {
         rename(PIMCORE_ASSET_DIRECTORY . $this->_oldPath, $this->getFileSystemPath());
     }
     if ($this->getType() != "folder") {
         // get data
         $this->getData();
         // remove if exists
         if (is_file($destinationPath)) {
             unlink($destinationPath);
         }
         file_put_contents($destinationPath, $this->getData());
         chmod($destinationPath, self::$chmod);
         // check file exists
         if (!is_file($destinationPath)) {
             throw new Exception("couldn't create new asset");
         }
         // set mime type
         $mimetype = MIME_Type::autoDetect($this->getFileSystemPath());
         $this->setMimetype($mimetype);
         // set type
         $this->setTypeFromMapping();
         // update scheduled tasks
         $this->saveScheduledTasks();
         // create version
         $this->getData();
         // load data from filesystem to put it into the version
         $version = new Version();
         $version->setCid($this->getId());
         $version->setCtype("asset");
         $version->setDate($this->getModificationDate());
         $version->setUserId($this->getUserModification());
         $version->setData($this);
         $version->save();
     }
     // save properties
     $this->getProperties();
     $this->getResource()->deleteAllProperties();
     if (is_array($this->getProperties()) and count($this->getProperties()) > 0) {
         foreach ($this->getProperties() as $property) {
             if (!$property->getInherited()) {
                 $property->setResource(null);
                 $property->setCid($this->getId());
                 $property->setCpath($this->getPath() . $this->getKey());
                 $property->save();
             }
         }
     }
     // save permissions
     $this->getPermissions();
     if (is_array($this->permissions)) {
         // remove all permissions
         $this->getResource()->deleteAllPermissions();
         foreach ($this->permissions as $permission) {
             $permission->setId(null);
             $permission->setCid($this->getId());
             $permission->setCpath($this->getFullPath());
             $permission->save();
         }
     }
     // save dependencies
     $d = $this->getDependencies();
     $d->clean();
     foreach ($this->resolveDependencies() as $requirement) {
         if ($requirement["id"] == $this->getId() && $requirement["type"] == "asset") {
             // dont't add a reference to yourself
             continue;
         } else {
             $d->addRequirement($requirement["id"], $requirement["type"]);
         }
     }
     $d->save();
     $this->getResource()->update();
     if ($this->_oldPath) {
         $this->getResource()->updateChildsPaths($this->_oldPath);
     }
     $this->clearDependedCache();
     //set object to registry
     Zend_Registry::set("asset_" . $this->getId(), $this);
     Pimcore_API_Plugin_Broker::getInstance()->postUpdateAsset($this);
 }
开发者ID:ngocanh,项目名称:pimcore,代码行数:98,代码来源:Asset.php



注:本文中的MIME_Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP MMCApp类代码示例发布时间:2022-05-23
下一篇:
PHP MG类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap