本文整理汇总了PHP中MIME_Type::autoDetect方法的典型用法代码示例。如果您正苦于以下问题:PHP MIME_Type::autoDetect方法的具体用法?PHP MIME_Type::autoDetect怎么用?PHP MIME_Type::autoDetect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MIME_Type
的用法示例。
在下文中一共展示了MIME_Type::autoDetect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: detect
public function detect($filepath)
{
return MIME_Type::autoDetect($filepath);
}
示例6: getMime
/**
* @see File_Archive_Reader::getMime
*/
function getMime()
{
if ($this->mime === null) {
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$this->mime = MIME_Type::autoDetect($this->getDataFilename());
PEAR::popErrorHandling();
if (PEAR::isError($this->mime)) {
$this->mime = parent::getMime();
}
}
return $this->mime;
}
示例7: ini_set
<?php
ini_set('error_reporting', E_ALL);
require 'MIME/Type.php';
//require './Type.php';
$type = 'application/x-test-app; foo="bar" (First argument); bar=baz (Second argument)';
$type2 = 'application/vnd.pear.test-type';
print "Checking type: {$type}\n";
if (MIME_Type::isExperimental($type)) {
print "Type is experimental\n";
} else {
print "Type is not experimental\n";
}
print "\nChecking type: {$type2}\n";
if (MIME_Type::isVendor($type2)) {
print "Type is vendor-specific\n";
} else {
print "Type is not vendor-specific\n";
}
$file = '/home/mini/workspace/Trunk/core/PEAR/docs/MIME_Type/example.php';
print "\nChecking type of: {$file}\n";
print MIME_Type::autoDetect($file) . "\n";
示例8: guessContentType
/**
* Guess content type of file
*
* First we try to use PEAR::MIME_Type, if installed, to detect the content
* type, else we check if ext/mime_magic is loaded and properly configured.
*
* Returns PEAR_Error if:
* o if PEAR::MIME_Type failed to detect a proper content type
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
* o ext/magic.mime is not installed, or not properly configured
* (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC)
* o mime_content_type() couldn't guess content type or returned
* a content type considered to be bogus by setContentType()
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
*
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
*/
function guessContentType()
{
if (class_exists('MIME_Type') || @(include_once 'MIME/Type.php')) {
if (PEAR::isError($mime_type = MIME_Type::autoDetect($this->file))) {
return PEAR::raiseError($mime_type->getMessage(), HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE);
}
return $this->setContentType($mime_type);
}
if (!function_exists('mime_content_type')) {
return PEAR::raiseError('This feature requires ext/mime_magic!', HTTP_DOWNLOAD_E_NO_EXT_MMAGIC);
}
if (!is_file(ini_get('mime_magic.magicfile'))) {
return PEAR::raiseError('ext/mime_magic is loaded but not properly configured!', HTTP_DOWNLOAD_E_NO_EXT_MMAGIC);
}
if (!($content_type = @mime_content_type($this->file))) {
return PEAR::raiseError('Couldn\'t guess content type with mime_content_type().', HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE);
}
return $this->setContentType($content_type);
}
示例9: 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);
}
示例10: testAutoDetectError
public function testAutoDetectError()
{
$mt = new MIME_Type();
$mt->useFinfo = false;
$mt->useMimeContentType = false;
$mt->useFileCmd = false;
$mt->useExtension = false;
$res = $mt->autoDetect(dirname(__FILE__) . '/files/example.jpg');
$this->assertInstanceOf('PEAR_Error', $res);
$this->assertEquals('', $mt->media);
$this->assertEquals('', $mt->subType);
}
示例11: 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;
}
}
示例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: 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]);
}
} else {
// probably this version of file is too old to understand "-b", try without
$cmd = $file_binary . " \"" . $file . "\"";
exec($cmd, $result);
// strip path from result
$result[0] = trim(substr($result[0], strlen($file) + 1));
// combine the results
$tmp_result = @explode(" ", $result[0]);
if (isset($tmp_result[2])) {
if ($tmp_result[2] == 'file') {
$mime = $tmp_result[1] . '/' . $tmp_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;
}
}
示例14: 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()
{
}
示例15: 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);
}
}
}