本文整理汇总了PHP中get_mimes函数的典型用法代码示例。如果您正苦于以下问题:PHP get_mimes函数的具体用法?PHP get_mimes怎么用?PHP get_mimes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_mimes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param array
* @return void
*/
public function __construct($props = array())
{
if (count($props) > 0) {
$this->initialize($props);
}
$this->mimes =& get_mimes();
log_message('debug', 'Upload Class Initialized');
}
示例2: __construct
public function __construct($namespace = 'xueba', $dir = '/')
{
$this->_mimes =& get_mimes();
$this->_CI =& get_instance();
$this->_CI->load->config('upload_images');
$this->config = $this->_CI->config->item('wanpitu');
$this->namespace = $namespace;
$this->dir = '/';
}
示例3: getMime
public static function getMime($name)
{
$mimes =& get_mimes();
$exp = explode('.', $name);
$extension = end($exp);
if (isset($mimes[$extension])) {
$mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
} else {
$mime = 'application/octet-stream';
}
return $mime;
}
示例4: force_download
/**
* Force Download
*
* Generates headers that force a download to happen
*
* @param string filename
* @param mixed the data to be downloaded
* @param bool whether to try and send the actual file MIME type
* @return void
*/
function force_download($filename = '', $data = '', $set_mime = FALSE)
{
if ($filename === '' or $data === '') {
return FALSE;
}
// Set the default MIME type to send
$mime = 'application/octet-stream';
$x = explode('.', $filename);
$extension = end($x);
if ($set_mime === TRUE) {
if (count($x) === 1 or $extension === '') {
/* If we're going to detect the MIME type,
* we'll need a file extension.
*/
return FALSE;
}
// Load the mime types
$mimes =& get_mimes();
// Only change the default MIME if we can find one
if (isset($mimes[$extension])) {
$mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
}
}
/* It was reported that browsers on Android 2.1 (and possibly older as well)
* need to have the filename extension upper-cased in order to be able to
* download it.
*
* Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
*/
if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
$x[count($x) - 1] = strtoupper($extension);
$filename = implode('.', $x);
}
// Clean output buffer
if (ob_get_level() !== 0) {
ob_clean();
}
// Generate the server headers
header('Content-Type: ' . $mime);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen($data));
// Internet Explorer-specific headers
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
exit($data);
}
示例5: common_functions
public function common_functions()
{
echo is_php('5.3');
echo is_really_writable('file.php');
echo config_item('key');
echo set_status_header('200', 'text');
echo remove_invisible_characters('Java\\0script');
echo html_escape(array());
echo get_mimes();
echo is_https();
echo is_cli();
echo function_usable('eval');
}
示例6: download
public static function download($uuid, $filename, $set_mime = TRUE)
{
$CI =& get_instance();
$config = $CI->config->item('utils');
list($secureId, $id, $path) = self::getData($uuid);
$filepath = $config['file_dir'] . $path . '/' . self::getFileName($id, $path) . '.backup';
$filesize = filesize($filepath);
$mime = 'application/octet-stream';
$x = explode('.', $filename);
$extension = end($x);
if ($set_mime === TRUE) {
if (count($x) === 1 or $extension === '') {
return;
}
$mimes =& get_mimes();
if (isset($mimes[$extension])) {
$mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
}
}
if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
$x[count($x) - 1] = strtoupper($extension);
$filename = implode('.', $x);
}
if (($fp = @fopen($filepath, 'rb')) === FALSE) {
return self::NOT_FOUND;
}
if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) {
@ob_clean();
}
header('Content-Type: ' . $mime);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . $filesize);
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
header('Cache-Control: no-cache, no-store, must-revalidate');
}
header('Pragma: no-cache');
while (!feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) {
echo $data;
}
fclose($fp);
exit;
}
示例7: GetResults
public function GetResults()
{
$mimes =& get_mimes();
$rootFolderID = NULL;
$items = NULL;
$folders = array();
if (get_inventory($this->User['UserID'], $rootFolderID, $items)) {
foreach ($items as $item) {
$type = isset($mimes[$item['ContentType']]) ? $mimes[$item['ContentType']] : -1;
$folders[] = array('folder_id' => $item['ID'], 'name' => $item['Name'], 'parent_id' => $item['ParentID'], 'version' => (int) $item['Version'], 'type_default' => (int) $type);
}
} else {
log_message('error', 'Failed to fetch inventory skeleton for ' . $this->User['UserID']);
// Allowing the viewer to login with an empty inventory skeleton does bad things. Better
// to just bail out
exit;
}
log_message('debug', 'Returning ' . count($folders) . ' inventory folders in the skeleton');
return $folders;
}
示例8: GetResults
public function GetResults()
{
$mimes =& get_mimes();
// Get the library owner ID
$userID = NULL;
if (!get_library_owner($userID)) {
log_message('warn', '[inventory_skel_lib] failed to get library owner');
return array();
} else {
// Get the root folder ID
$rootFolderID = $userID;
if (!get_library_root_folder($userID, $rootFolderID)) {
log_message('warn', '[inventory_skel_lib] failed to get library root');
return array();
}
// Get the items from the inventory folder
$items = NULL;
if (!get_inventory_items($userID, $rootFolderID, 0, $items)) {
log_message('warn', '[inventory_skel_lib] failed to get library contents');
return array();
}
// Build the output folder structure
$folders = array();
foreach ($items as $item) {
$type = isset($mimes[$item['ContentType']]) ? $mimes[$item['ContentType']] : -1;
$parentid = $item['ParentID'];
$folderid = $item['ID'];
$foldername = $item['Name'];
if ($folderid == $rootFolderID) {
$parentid = '00000000-0000-0000-0000-000000000000';
}
$folders[] = array('folder_id' => $folderid, 'name' => $foldername, 'parent_id' => $parentid, 'version' => (int) $item['Version'], 'type_default' => (int) $type);
}
log_message('debug', sprintf('[inventory_skel_lib] %d folders from %s owned by %s', count($folders), $rootFolderID, $userID));
return $folders;
}
}
示例9: qiniu_upload
function qiniu_upload($name, $type = 'gif|jpg|png')
{
$tmp_file = $_FILES[$name];
if (!isset($tmp_file['name']) || isset($tmp_file['name']) && empty($tmp_file['name'])) {
return '';
}
$minis =& get_mimes();
$type = explode('|', $type);
$flag = FALSE;
foreach ($type as $item) {
if (isset($minis[$item])) {
if (is_array($minis[$item]) && in_array($tmp_file['type'], $minis[$item]) || is_string($minis[$item]) && $tmp_file['type'] == $minis[$item]) {
$flag = TRUE;
}
}
}
if (!$flag) {
return FALSE;
}
$CI =& get_instance();
$CI->load->model('qiniu_model', 'qiniu');
if (isset($_SESSION['qiniu_token'])) {
$token = $_SESSION['qiniu_token'];
} else {
$token = $CI->qiniu->get_token();
$CI->session->set_tempdata('qiniu_token', $token, 3000);
}
$file_name = 'ci_set/' . date('Y/m/dH/i/s', time()) . md5(substr($tmp_file['name'], 0, strrpos($tmp_file['name'], '.')) . time()) . substr($tmp_file['name'], strrpos($tmp_file['name'], '.'));
$ret = $CI->qiniu->upload_file($token, $tmp_file['tmp_name'], $file_name);
if (isset($ret['key'])) {
return $ret['key'];
}
return FALSE;
}
示例10: __construct
/**
* Class constructor.
*
* Determines whether zLib output compression will be used.
*
* @return void
*/
public function __construct()
{
$this->_zlib_oc = (bool) ini_get('zlib.output_compression');
$this->_compress_output = $this->_zlib_oc === false && config_item('compress_output') === true && extension_loaded('zlib');
// Get mime types for later
$this->mimes =& get_mimes();
log_message('info', 'Output Class Initialized');
}
示例11: view
public function view($file, $type)
{
global $ci, $page;
$file .= '.' . $type;
$type = strtolower($type);
$image = $compress = $deliver = $download = $stream = false;
if (preg_match('/^(jpe?g|gif|png|ico)$/', $type)) {
$image = $type;
} elseif (preg_match('/^(js|css|pdf|ttf|otf|svg)$/', $type)) {
$compress = $type;
} elseif (preg_match('/^(eot|woff2?|swf)$/', $type)) {
$deliver = $type;
} elseif (preg_match('/^(tar|t?gz|zip|csv|xls?x?|word|docx?|ppt|psd)$/', $type)) {
$download = $type;
} elseif (preg_match('/^(ogg|wav|mp3|mp4|mpeg?|mpg|mov|qt)$/', $type)) {
$stream = $type;
} else {
exit(header('HTTP/1.1 503 Not Implemented'));
}
if ($this->cached($file)) {
list($files, $updated) = $this->file_paths($file);
if (empty($files)) {
exit(header('HTTP/1.1 404 Not Found'));
}
$cache = array_shift($files);
// Only one file at a time is allowed now
$updated = array_shift($updated);
if (preg_match('/^.{5}\\/((~)?([0-9]{1,3})[x]{1}([0-9]{1,3})(:[0-9]{1,3})?)[\\/\\.]{1}/', $file, $matches)) {
$thumb = BASE_URI . 'thumbs/' . md5($cache) . '/' . rawurlencode($matches[1]) . '.' . $type;
if (!is_file($thumb) || filemtime($thumb) < $updated) {
// create the image thumb
require_once BASE . 'Page.php';
$page = new Page();
$thumbnail = $page->plugin('Image', 'uri', $cache);
if ($matches[2] == '~') {
$thumbnail->constrain($matches[3], $matches[4]);
} else {
$thumbnail->resize($matches[3], $matches[4], 'enforce');
}
$thumbnail->save($thumb, isset($matches[5]) ? min(substr($matches[5], 1), 100) : 80);
}
$cache = $thumb;
$updated = filemtime($thumb);
}
if (!$download && !$stream) {
$this->never_expires($updated);
}
if ($compress == 'pdf' || $download || $stream) {
$ci->load->driver('session');
$resource = str_replace(array(BASE_URI, BASE), '', $cache);
$resource .= '#' . substr(strstr($ci->uri->uri_string(), '/'), 1);
$ci->log_analytics('hits', $resource);
}
} elseif (strpos($file, 'CDN') !== false && is_file(BASE . $file)) {
$cache = BASE . $file;
$this->never_expires(filemtime($cache));
} elseif ($file == 'favicon.ico') {
$cache = dirname(__DIR__) . DIRECTORY_SEPARATOR . $file;
$this->never_expires(filemtime($cache));
} else {
exit(header('HTTP/1.1 404 Not Found'));
}
$mimes =& get_mimes();
header('Content-Type: ' . (is_array($mimes[$type]) ? array_shift($mimes[$type]) : $mimes[$type]));
if ($compress) {
$supported = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
$gzip = strstr($supported, 'gzip');
$deflate = strstr($supported, 'deflate');
$encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
if (isset($_SERVER['HTTP_USER_AGENT']) && !strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && preg_match('/^Mozilla\\/4\\.0 \\(compatible; MSIE ([0-9]\\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
$version = floatval($matches[1]);
if ($version < 6) {
$encoding = 'none';
}
if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) {
$encoding = 'none';
}
}
$cache = $type == 'css' ? $this->css_get_contents($cache, $file) : file_get_contents($cache);
if ($encoding != 'none') {
$cache = gzencode($cache, 9, $encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE);
header('Vary: Accept-Encoding');
header('Content-Encoding: ' . $encoding);
}
header('Content-Length: ' . strlen($cache));
exit($cache);
}
if (!($fp = fopen($cache, 'rb'))) {
header('HTTP/1.1 500 Internal Server Error');
exit;
}
$size = filesize($cache);
if ($download || $stream) {
ini_set('zlib.output_compression', 'Off');
$length = $size;
$start = 0;
$end = $size - 1;
if ($range = $ci->input->server('HTTP_RANGE')) {
// serve a partial file
if (preg_match('%bytes=(\\d+)-(\\d+)?%i', $range, $match)) {
//.........这里部分代码省略.........
示例12: __construct
/**
* Constructor
*
* @param array $props
* @return void
*/
public function __construct($config = array())
{
empty($config) or $this->initialize($config, FALSE);
$this->_mimes =& get_mimes();
$this->_CI =& get_instance();
log_message('info', 'Upload Class Initialized');
}
示例13: _mime_types
/**
* Mime Types
*
* @param string
* @return string
*/
protected function _mime_types($ext = '')
{
$ext = strtolower($ext);
$mimes =& get_mimes();
if (isset($mimes[$ext])) {
return is_array($mimes[$ext]) ? current($mimes[$ext]) : $mimes[$ext];
}
return 'application/x-unknown-content-type';
}
示例14: force_download
/**
* Force Download
* 推动强迫下载
* Generates headers that force a download to happen
* 生成头文件强制下载发生
* @param string filename 文件名称
* @param mixed the data to be downloaded 下载的数据
* @param bool whether to try and send the actual file MIME type 是否要试着发送实际的文件的MIME类型
* @return void
*/
function force_download($filename = '', $data = '', $set_mime = FALSE)
{
if ($filename === '' or $data === '') {
return;
} elseif ($data === NULL) {
if (!@is_file($filename) or ($filesize = @filesize($filename)) === FALSE) {
return;
}
$filepath = $filename;
$filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
$filename = end($filename);
} else {
$filesize = strlen($data);
}
// Set the default MIME type to send 设置默认发送MIME类型
$mime = 'application/octet-stream';
$x = explode('.', $filename);
$extension = end($x);
if ($set_mime === TRUE) {
if (count($x) === 1 or $extension === '') {
/* If we're going to detect the MIME type, 如果我们要检测的MIME类型,
* we'll need a file extension. 我们需要一个文件扩展名。
*/
return;
}
// Load the mime types 加载mime类型
$mimes =& get_mimes();
// Only change the default MIME if we can find one 只改变默认的MIME如果我们能找到一个
if (isset($mimes[$extension])) {
$mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
}
}
/* It was reported that browsers on Android 2.1 (and possibly older as well)
* need to have the filename extension upper-cased in order to be able to
* download it.
* 据报道,浏览器在Android 2.1(也可能是旧的)需要文件扩展名大写为了能够下载它。
* Reference参考: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
*/
if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\\s(1|2\\.[01])/', $_SERVER['HTTP_USER_AGENT'])) {
$x[count($x) - 1] = strtoupper($extension);
$filename = implode('.', $x);
}
if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE) {
return;
}
// Clean output buffer 干净的输出缓冲区
if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) {
@ob_clean();
}
// Generate the server headers 生成服务器头信息
header('Content-Type: ' . $mime);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . $filesize);
header('Cache-Control: private, no-transform, no-store, must-revalidate');
// If we have raw data - just dump it 如果我们有原始数据,将扔弃它
if ($data !== NULL) {
exit($data);
}
// Flush 1MB chunks of data 冲洗1MB的数据块
while (!feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) {
echo $data;
}
fclose($fp);
exit;
}
示例15: __construct
/**
* Class constructor
*
* Determines whether zLib output compression will be used.
*
* @return void
*/
public function __construct()
{
// global $BM, $CFG;
$CFG =& load_class('Config', 'core');
$BM =& load_class('Benchmark', 'core');
$this->_zlib_oc = (bool) ini_get('zlib.output_compression');
$this->_compress_output = $this->_zlib_oc === FALSE && config_item('compress_output') === TRUE && extension_loaded('zlib');
// Get mime types for later
$this->mimes =& get_mimes();
log_message('info', 'Output Class Initialized');
}