本文整理汇总了PHP中mimetype函数的典型用法代码示例。如果您正苦于以下问题:PHP mimetype函数的具体用法?PHP mimetype怎么用?PHP mimetype使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mimetype函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler)
{
global $ID;
$match = substr($match, 9, -11);
// strip markup
list($flags, $match) = explode('>', $match, 2);
$flags = explode('&', substr($flags, 1));
$items = explode('*', $match);
$pages = array();
$c = count($items);
for ($i = 0; $i < $c; $i++) {
if (!preg_match('/\\[\\[(.+?)\\]\\]/', $items[$i], $match)) {
continue;
}
list($id, $title, $description) = explode('|', $match[1], 3);
list($id, $section) = explode('#', $id, 2);
if (!$id) {
$id = $ID;
}
resolve_pageid(getNS($ID), $id, $exists);
// page has an image title
if ($title && preg_match('/\\{\\{(.+?)\\}\\}/', $title, $match)) {
list($image, $title) = explode('|', $match[1], 2);
list($ext, $mime) = mimetype($image);
if (!substr($mime, 0, 5) == 'image') {
$image = '';
}
$pages[] = array('id' => $id, 'section' => cleanID($section), 'title' => trim($title), 'image' => trim($image), 'description' => trim($description), 'exists' => $exists);
// text title (if any)
} else {
$pages[] = array('id' => $id, 'section' => cleanID($section), 'title' => trim($title), 'description' => trim($description), 'exists' => $exists);
}
}
return array($flags, $pages);
}
示例2: add_file_callback
private static function add_file_callback($id, $new_file, $filename)
{
$CI =& get_instance();
$hash = md5_file($new_file);
$storage_id = null;
$query = $CI->db->select('id, hash')->from('file_storage')->where('hash', $hash)->get()->result_array();
foreach ($query as $row) {
$data_id = implode("-", array($row['hash'], $row['id']));
$old_file = $CI->mfile->file($data_id);
// TODO: set $new_file
if (files_are_equal($old_file, $new_file)) {
$storage_id = $row["id"];
break;
}
}
if ($storage_id === null) {
$filesize = filesize($new_file);
$mimetype = mimetype($new_file);
$CI->db->insert("file_storage", array("filesize" => $filesize, "mimetype" => $mimetype, "hash" => $hash, "date" => time()));
$storage_id = $CI->db->insert_id();
}
$data_id = $hash . "-" . $storage_id;
// TODO: all this doesn't have to run if the file exists. updating the mtime would be enough
// that would also be better for COW filesystems
$dir = $CI->mfile->folder($data_id);
file_exists($dir) || mkdir($dir);
$new_path = $CI->mfile->file($data_id);
$dest = new \service\storage($new_path);
$tmpfile = $dest->begin();
rename($new_file, $tmpfile);
$dest->commit();
$CI->mfile->add_file($id, $filename, $storage_id);
}
示例3: handle_output
function handle_output(&$event, $param)
{
if ($event->data['do'] != 'imageshack') {
return;
}
global $lang;
echo '<h1 id="media__ns">' . $this->getLang('name') . '</h1>';
echo '<p>' . $this->getLang('intro') . '</p>';
echo '<form action="' . DOKU_BASE . 'lib/exe/mediamanager.php" method="post" enctype="multipart/form-data">';
echo '<input type="hidden" name="do" value="imageshack" />';
echo '<input type="file" name="imageshack_file" />';
echo '<input type="submit" value="' . $lang['btn_upload'] . '" class="button" />';
echo '</form>';
// output the uploads stored in the current session
if (is_array($_SESSION['imageshack'])) {
$files = array_reverse($_SESSION['imageshack']);
$twibble = 1;
foreach ($files as $item) {
$twibble *= -1;
$zebra = $twibble == -1 ? 'odd' : 'even';
list($ext, $mime, $dl) = mimetype($item['name']);
$class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
$class = 'select mediafile mf_' . $class;
echo '<div class="' . $zebra . '">' . NL;
echo '<a name="h_' . $item['link'] . '" class="' . $class . '">' . hsc($item['name']) . '</a> ';
echo '<span class="info">(' . $item['width'] . '×' . $item['height'] . ' ' . filesize_h($item['size']) . ')</span>' . NL;
echo ' <a href="' . $item['adlink'] . '" target="_blank"><img src="' . DOKU_BASE . 'lib/images/magnifier.png" ' . 'alt="' . $lang['mediaview'] . '" title="' . $lang['mediaview'] . '" class="btn" /></a>' . NL;
echo '<div class="example" id="ex_' . str_replace(':', '_', $item['link']) . '">';
echo $lang['mediausage'] . ' <code>{{' . hsc($item['link']) . '}}</code>';
echo '</div>';
if ($item['width'] > 120 || $item['height'] > 100) {
$w = 120;
$h = 100;
} else {
$w = $item['width'];
$h = $item['height'];
}
$src = ml($item['link'], array('w' => $w, 'h' => $h));
$p = array();
$p['width'] = $w;
$p['height'] = $h;
$p['alt'] = $item['name'];
$p['class'] = 'thumb';
$att = buildAttributes($p);
// output
echo '<div class="detail">';
echo '<div class="thumb">';
echo '<a name="d_' . $item['link'] . '" class="select">';
echo '<img src="' . $src . '" ' . $att . ' />';
echo '</a>';
echo '</div>';
echo '</div>';
echo '<div class="clearer"></div>' . NL;
echo '</div>' . NL;
}
}
$event->preventDefault();
}
示例4: addFileAsPicture
/**
* Adds the file $src as a picture file without adding it to the content.
* Returns name of the file in the document for reference.
*
* @param string $src
* @return string
*/
function addFileAsPicture($src)
{
$name = '';
if (file_exists($src)) {
list($ext, $mime) = mimetype($src);
$name = 'Pictures/' . md5($src) . '.' . $ext;
$this->addFile($name, $mime, io_readfile($src, false));
}
return $name;
}
示例5: _media
function _media($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL)
{
$ret = '';
list($ext, $mime) = mimetype($src);
if (substr($mime, 0, 5) == 'image') {
//add image tag
$ret .= '<img src="media/' . str_replace(':', '/', $src) . '"';
$ret .= ' class="media' . $align . '"';
if (!is_null($title)) {
$ret .= ' title="' . $this->_xmlEntities($title) . '"';
$ret .= ' alt="' . $this->_xmlEntities($title) . '"';
} else {
$ret .= ' alt=""';
}
if (!is_null($width)) {
$ret .= ' width="' . $this->_xmlEntities($width) . '"';
}
if (!is_null($height)) {
$ret .= ' height="' . $this->_xmlEntities($height) . '"';
}
$ret .= ' />';
} elseif ($mime == 'application/x-shockwave-flash') {
$ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' . ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
if (!is_null($width)) {
$ret .= ' width="' . $this->_xmlEntities($width) . '"';
}
if (!is_null($height)) {
$ret .= ' height="' . $this->_xmlEntities($height) . '"';
}
$ret .= '>' . DOKU_LF;
$ret .= '<param name="movie" value="media/' . str_replace(':', '/', $src) . '" />' . DOKU_LF;
$ret .= '<param name="quality" value="high" />' . DOKU_LF;
$ret .= '<embed src="media/' . str_replace(':', '/', $src) . '"' . ' quality="high"';
if (!is_null($width)) {
$ret .= ' width="' . $this->_xmlEntities($width) . '"';
}
if (!is_null($height)) {
$ret .= ' height="' . $this->_xmlEntities($height) . '"';
}
$ret .= ' type="application/x-shockwave-flash"' . ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' . DOKU_LF;
$ret .= '</object>' . DOKU_LF;
} elseif (!is_null($title)) {
// well at least we have a title to display
$ret .= $this->_xmlEntities($title);
} else {
// just show the source
$ret .= $this->_xmlEntities($src);
}
return $ret;
}
示例6: renderValue
/**
* Output the stored data
*
* If outputted in an aggregation we collect the images into a gallery.
*
* @param string|int $value the value stored in the database
* @param \Doku_Renderer $R the renderer currently used to render the data
* @param string $mode The mode the output is rendered in (eg. XHTML)
* @return bool true if $mode could be satisfied
*/
public function renderValue($value, \Doku_Renderer $R, $mode)
{
// get width and height from config
$width = null;
$height = null;
if ($this->config['width']) {
$width = $this->config['width'];
}
if ($this->config['height']) {
$height = $this->config['height'];
}
if (!empty($R->info['struct_table_hash'])) {
// this is an aggregation, check for special values
if ($this->config['agg_width']) {
$width = $this->config['agg_width'];
}
if ($this->config['agg_height']) {
$height = $this->config['agg_height'];
}
}
// depending on renderer type directly output or get value from it
$returnLink = null;
$html = '';
if (!media_isexternal($value)) {
if (is_a($R, '\\Doku_Renderer_xhtml')) {
/** @var \Doku_Renderer_xhtml $R */
$html = $R->internalmedia($value, null, null, $width, $height, null, 'direct', true);
} else {
$R->internalmedia($value, null, null, $width, $height, null, 'direct');
}
} else {
if (is_a($R, '\\Doku_Renderer_xhtml')) {
/** @var \Doku_Renderer_xhtml $R */
$html = $R->externalmedia($value, null, null, $width, $height, null, 'direct', true);
} else {
$R->externalmedia($value, null, null, $width, $height, null, 'direct');
}
}
// add gallery meta data in XHTML
if ($mode == 'xhtml') {
list(, $mime, ) = mimetype($value, false);
if (substr($mime, 0, 6) == 'image/') {
$hash = !empty($R->info['struct_table_hash']) ? "[gal-" . $R->info['struct_table_hash'] . "]" : '';
$html = str_replace('href', "rel=\"lightbox{$hash}\" href", $html);
}
$R->doc .= $html;
}
return true;
}
示例7: moveMediaAttic
/**
* Move the old revisions of the media file that is specified in the options
*
* @param string $src_ns The original namespace
* @param string $src_name The original basename of the moved doc (empty for namespace moves)
* @param string $dst_ns The namespace after the move
* @param string $dst_name The basename after the move (empty for namespace moves)
* @return bool If the attic files were moved successfully
*/
public function moveMediaAttic($src_ns, $src_name, $dst_ns, $dst_name)
{
global $conf;
$ext = mimetype($src_name);
if ($ext[0] !== false) {
$name = substr($src_name, 0, -1 * strlen($ext[0]) - 1);
} else {
$name = $src_name;
}
$newext = mimetype($dst_name);
if ($newext[0] !== false) {
$newname = substr($dst_name, 0, -1 * strlen($newext[0]) - 1);
} else {
$newname = $dst_name;
}
$regex = '\\.\\d+\\.' . preg_quote((string) $ext[0], '/');
return $this->execute($conf['mediaolddir'], $src_ns, $name, $dst_ns, $newname, $regex);
}
示例8: __construct
public function __construct()
{
// Prepare
parent::__construct();
$manager = new Manager(new ArrayDriver());
$this->__lock = $manager->caller(new Path());
$this->__lock->deny('all');
// REST
$this->middleware(function ($middlewares) {
if (isset($_POST['_METHOD'])) {
$_SERVER['REQUEST_METHOD'] = strtoupper($_POST['_METHOD']);
unset($_POST['_METHOD']);
}
$middlewares->next();
});
// Return allowed files
$this->middleware(function ($middlewares) {
$path = $this->_formatPath($this['request']->getResourceUri());
if (file_exists($path) && is_file($path) && $this->__lock->can($this->_formatPath($path))) {
// Get mime type
$mime = mimetype($path);
// Try some more extensions
if ($mime == 'text/plain') {
if (strpos($path, '.css')) {
$mime = 'text/css';
}
if (strpos($path, '.js')) {
$mime = 'application/javascript';
}
if (strpos($path, '.json')) {
$mime = 'application/json';
}
}
// Set content type
if ($mime != 'text/plain') {
header('Content-Type: ' . $mime);
}
// Print file
echo file_get_contents($path);
exit;
}
$middlewares->next();
});
}
示例9: sl_upload
function sl_upload($srcFile, $dstFile)
{
$uploadType = Get::cfg('uploadType');
// check if the mime type is allowed by the whitelist
// if the whitelist is empty all types are accepted
require_once _lib_ . '/lib.mimetype.php';
$upload_whitelist = Get::sett('file_upload_whitelist', 'zip,jpg,gif,png,txt,csv,rtf,xml,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp,pdf,xps,mp4,mp3,flv,swf,mov,wav,ogg,flac,wma,wmv');
$upload_whitelist_arr = explode(',', trim($upload_whitelist, ','));
if (!empty($upload_whitelist_arr)) {
$valid_ext = false;
$file_ext = strtolower(substr(strrchr($dstFile, "."), 1));
foreach ($upload_whitelist_arr as $k => $v) {
// remove extra spaces and set lower case
$ext = trim(strtolower($v));
$mt = mimetype($ext);
if ($mt) {
$mimetype_arr[] = $mt;
}
getOtherMime($ext, $mimetype_arr);
if ($ext == $file_ext) {
$valid_ext = true;
}
}
$mimetype_arr = array_unique($mimetype_arr);
if (class_exists('file') && method_exists('finfo', 'file')) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$file_mime_type = $finfo->file($srcFile);
} else {
$file_mime_type = mime_content_type($srcFile);
}
if (!$valid_ext || !in_array($file_mime_type, $mimetype_arr)) {
return false;
}
}
$dstFile = stripslashes($dstFile);
if ($uploadType == "ftp") {
return sl_upload_ftp($srcFile, $dstFile);
} elseif ($uploadType == "cgi") {
return sl_upload_cgi($srcFile, $dstFile);
} else {
return sl_upload_fs($srcFile, $dstFile);
}
}
示例10: download
function download($path, $home, $force = true)
{
if (is_file($home . $path) && $force) {
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($path) . '";');
header('Content-Transfer-Encoding: binary');
readfile($home . $path);
} elseif (is_file($home . $path)) {
header('Content-type: ' . mimetype($home . $path));
readfile($home . $path);
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
header('Status: 404 Not Found');
$_SERVER['REDIRECT_STATUS'] = 404;
if (!$force) {
echo 'The requested file is not available.';
}
}
}
示例11: internalmedia
public function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL, $return = false)
{
global $ID;
list($src, $hash) = explode('#', $src, 2);
resolve_mediaid(getNS($ID), $src, $exists);
$noLink = false;
$render = $linking == 'linkonly' ? false : true;
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
list($ext, $mime, $dl) = mimetype($src, false);
if (substr($mime, 0, 5) == 'image' && $render) {
if ($linking == NULL || $linking == '' || $linking == 'details') {
$linking = 'direct';
}
$link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), $linking == 'direct');
} elseif ($mime == 'application/x-shockwave-flash' && $render) {
// don't link flash movies
$noLink = true;
} else {
// add file icons
$class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
$link['class'] .= ' mediafile mf_' . $class;
$link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
if ($exists) {
$link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))) . ')';
}
}
if ($hash) {
$link['url'] .= '#' . $hash;
}
//markup non existing files
if (!$exists) {
$link['class'] .= ' wikilink2';
}
//output formatted
if ($linking == 'nolink' || $noLink) {
$this->doc .= $link['name'];
} else {
$this->doc .= $this->_formatLink($link);
}
}
示例12: _media
/**
* Renders internal and external media
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function _media($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $render = true)
{
$ret = '';
list($ext, $mime, $dl) = mimetype($src);
if (substr($mime, 0, 5) == 'image') {
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);
} elseif ($ext == 'jpg' || $ext == 'jpeg') {
//try to use the caption from IPTC/EXIF
require_once DOKU_INC . 'inc/JpegMeta.php';
$jpeg = new JpegMeta(mediaFN($src));
if ($jpeg !== false) {
$cap = $jpeg->getTitle();
}
if ($cap) {
$title = $this->_xmlEntities($cap);
}
}
if (!$render) {
// if the picture is not supposed to be rendered
// return the title of the picture
if (!$title) {
// just show the sourcename
$title = $this->_xmlEntities(utf8_basename(noNS($src)));
}
return $title;
}
//add image tag
$ret .= '<img src="' . ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache)) . '"';
$ret .= ' class="media' . $align . '"';
if ($title) {
$ret .= ' title="' . $title . '"';
$ret .= ' alt="' . $title . '"';
} else {
$ret .= ' alt=""';
}
if (!is_null($width)) {
$ret .= ' width="' . $this->_xmlEntities($width) . '"';
}
if (!is_null($height)) {
$ret .= ' height="' . $this->_xmlEntities($height) . '"';
}
$ret .= ' />';
} elseif ($mime == 'application/x-shockwave-flash') {
if (!$render) {
// if the flash is not supposed to be rendered
// return the title of the flash
if (!$title) {
// just show the sourcename
$title = utf8_basename(noNS($src));
}
return $this->_xmlEntities($title);
}
$att = array();
$att['class'] = "media{$align}";
if ($align == 'right') {
$att['align'] = 'right';
}
if ($align == 'left') {
$att['align'] = 'left';
}
$ret .= html_flashobject(ml($src, array('cache' => $cache), true, '&'), $width, $height, array('quality' => 'high'), null, $att, $this->_xmlEntities($title));
} elseif ($title) {
// well at least we have a title to display
$ret .= $this->_xmlEntities($title);
} else {
// just show the sourcename
$ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
}
return $ret;
}
示例13: define
*/
if (!defined('DOKU_INC')) {
define('DOKU_INC', dirname(__FILE__) . '/../../');
}
define('DOKU_DISABLE_GZIP_OUTPUT', 1);
require_once DOKU_INC . 'inc/init.php';
//close session
session_write_close();
$mimetypes = getMimeTypes();
//get input
$MEDIA = stripctl(getID('media', false));
// no cleaning except control chars - maybe external
$CACHE = calc_cache($_REQUEST['cache']);
$WIDTH = (int) $_REQUEST['w'];
$HEIGHT = (int) $_REQUEST['h'];
list($EXT, $MIME, $DL) = mimetype($MEDIA, false);
if ($EXT === false) {
$EXT = 'unknown';
$MIME = 'application/octet-stream';
$DL = true;
}
// check for permissions, preconditions and cache external files
list($STATUS, $STATUSMESSAGE) = checkFileStatus($MEDIA, $FILE);
// prepare data for plugin events
$data = array('media' => $MEDIA, 'file' => $FILE, 'orig' => $FILE, 'mime' => $MIME, 'download' => $DL, 'cache' => $CACHE, 'ext' => $EXT, 'width' => $WIDTH, 'height' => $HEIGHT, 'status' => $STATUS, 'statusmessage' => $STATUSMESSAGE);
// handle the file status
$evt = new Doku_Event('FETCH_MEDIA_STATUS', $data);
if ($evt->advise_before()) {
// redirects
if ($data['status'] > 300 && $data['status'] <= 304) {
send_redirect($data['statusmessage']);
示例14: mediaFN
/**
* returns the full path to the mediafile specified by ID
*
* The filename is URL encoded to protect Unicode chars
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Kate Arzamastseva <pshns@ukr.net>
*
* @param string $id media id
* @param string|int $rev empty string or revision timestamp
* @return string full path
*/
function mediaFN($id, $rev = '')
{
global $conf;
$id = cleanID($id);
$id = str_replace(':', '/', $id);
if (empty($rev)) {
$fn = $conf['mediadir'] . '/' . utf8_encodeFN($id);
} else {
$ext = mimetype($id);
$name = substr($id, 0, -1 * strlen($ext[0]) - 1);
$fn = $conf['mediaolddir'] . '/' . utf8_encodeFN($name . '.' . (int) $rev . '.' . $ext[0]);
}
return $fn;
}
示例15: emailer
//.........这里部分代码省略.........
#
#
default:
$x_prio = '3 (Normal)';
# 12/08/2009
}
if ($x_prio) {
$headers .= 'X-Priority: ' . $x_prio . _CR_;
}
#
# Message Priority for Exchange Servers
#
# $headers .= 'X-MSmail-Priority: '.$x_prio_des._CR_;
#
# !!! WARNING !!!---# Hotmail and others do NOT like PHP mailer...
# $headers .= 'X-Mailer: PHP/'.phpversion()._CR_;---#
#
# $headers .= 'X-Mailer: Microsoft Office Outlook, Build 11.0.6353'._CR_;
# $headers .= 'X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527'._CR_;
#
// $headers .= 'X-Sender: '.$_SESSION['misc']['E_ROBOT']._CR_;
$headers .= 'X-Sender: ' . $user_id . ' <' . $from_id . '>' . _CR_;
# 12/08/2009
$headers .= 'X-AntiAbuse: This is a solicited email for - ' . $to . ' - ' . _CR_;
$headers .= 'X-AntiAbuse: Servername - {' . $domain . '}' . _CR_;
// $headers .= 'X-AntiAbuse: User - '.$_SESSION['misc']['E_ROBOT']._CR_;
$headers .= 'X-AntiAbuse: User - ' . $from_id . _CR_;
# 12/08/2009
#
# Set the right start of header
#
// if($attach_file) # 25/11/2009
if ($attach_path && $attach_file) {
include SITE_ROOT . 'common/fun2inc/mimetype.inc';
#
# INS 25/11/2009 : BEG
#---------------------
if (!is_array($attach_path) || !is_array($attach_file)) {
$_attach_path = array();
$_attach_file = array();
$_attach_path[] = $attach_path;
$_attach_file[] = $attach_file;
} else {
$_attach_path = $attach_path;
$_attach_file = $attach_file;
}
#
$a = 0;
foreach ($_attach_file as $key => $attach_file) {
$attach_path = $_attach_path[$key];
#---------------------
# INS 25/11/2009 : END
#
$file_name_type = mimetype($attach_path, $attach_file);
$file_name_name = $attach_file;
#
# Read the file to be attached
#
$data = '';
// $file = @fopen($attach_path.$attach_file,'rb') or die('(emailer.inc) Cannot open: '.$attach_path.$attach_file);
$file = @fopen($attach_path . $attach_file, 'rb');
# 12/08/2009
if ($file) {
while (!feof($file)) {
$data .= @fread($file, 4096);
}