本文整理汇总了PHP中mime_type函数的典型用法代码示例。如果您正苦于以下问题:PHP mime_type函数的具体用法?PHP mime_type怎么用?PHP mime_type使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mime_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download_file
/**
* Prompts user for direct download of HTTP attachment.
* @param string $content
* @param string $ext
* @return void
*/
function download_file($content = '', $ext = '', $filename = NULL)
{
//Try to get the mime type
if (!($mime = mime_type($ext))) {
$mime = 'application/octet-stream';
}
//Create a random filename
if (!$filename) {
$filename = time() . '.' . $ext;
}
// Generate the server headers
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: " . strlen($data));
} else {
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: " . strlen($data));
}
//Send file
exit($content);
}
示例2: _outputFile
function _outputFile($_file)
{
Kurogo::log(LOG_DEBUG, "Output file {$_file}", 'kurogo');
if ($file = Watchdog::safePath($_file)) {
CacheHeaders($file);
header('Content-type: ' . mime_type($file));
readfile($file);
exit;
}
_404();
}
示例3: test_file_mime_type
function test_file_mime_type()
{
$mimes = mime_type();
assert_true(is_array($mimes));
assert_not_empty($mimes);
assert_empty(mime_type(''));
assert_equal(mime_type('txt'), 'text/plain');
assert_equal(mime_type('TXT'), 'text/plain');
assert_equal(mime_type('jpg'), 'image/jpeg');
assert_equal(mime_type('JPG'), 'image/jpeg');
}
示例4: mime_type_from_path
function mime_type_from_path($path)
{
$result = FALSE;
if ($path) {
$mime = mime_from_path($path);
if ($mime) {
$result = mime_type($mime);
}
}
return $result;
}
示例5: _outputFileLoaderFile
function _outputFileLoaderFile($matches) {
$fullPath = FileLoader::load($matches[1]);
if ($fullPath) {
CacheHeaders($fullPath);
header('Content-type: '.mime_type($fullPath));
echo file_get_contents($fullPath);
exit;
}
_404();
}
示例6: getminutes
}
$tmp = "";
//do we have an audio file? link to it here!
if ($audiothere) {
$tmp .= "<p><a href=\"" . $audiourl . "\">File Download ";
$tmp .= "(" . getminutes($comfields['audio_length']) . " min / " . getmegabyte($comfields['audio_size']) . " MB)</a>";
}
echo trim(htmlspecialchars($tmp, ENT_QUOTES));
echo "</content:encoded>\n";
//date of publication
echo " <pubDate>" . date("r", strtotime($comfields['posted'])) . "</pubDate>\n\n";
//do we add an enclosure?
if ($audiothere) {
echo " <enclosure url=\"" . $audiourl . "\" ";
echo "length=\"" . $comfields['audio_size'] . "\" ";
echo "type=\"" . mime_type($comfields['audio_type']) . "\" />\n";
echo " <itunes:duration>" . getitunesduration($comfields['audio_length']) . "</itunes:duration>\n";
}
echo "</item>\n\n";
}
}
}
echo "\n\n</channel>\n\n</rss>";
// ------------------------------------- FUNCTIONS -----------------------------
function showcats($fields)
{
global $settings;
global $cat_table;
//iTunes Categories
$allcats = array($settings['feedcat1'], $settings['feedcat2'], $settings['feedcat3'], $settings['feedcat4']);
$tunecats = "";
示例7: handleUpload
function handleUpload()
{
/***
* Determine the type of file upload handler that needs to be
* used, then pass things along accordingly.
***/
if (empty($_FILES)) {
return array('status' => false,'error' => 'No files provided','human_error' => 'Please provide a file to upload');
}
$temp = $_FILES['file']['tmp_name'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $temp);
finfo_close($finfo);
$file = $_FILES['file']['name'];
$mime_error = "";
if(empty($mime)) {
# Just the fallback that is based purely on extension
# Only used when finfo can't find a mime type
try {
$mime = mime_type($file);
} catch (Exception $e) {
$mime_error = $e->getMessage();
$mime = null;
}
}
# Look at the MIME prefix
$mime_types = explode('/', $mime);
$mime_class = $mime_types[0];
# Now, call the actual uploader function based on the mime class
# (eg, image/, audio/, video/ ... )
switch ($mime_class) {
case 'image':
return doUploadImage($mime);
break;
case 'audio':
return doUploadAudio($mime);
break;
case 'video':
return doUploadVideo($mime);
break;
default:
# return array('status' => false,'error' => "Unrecognized MIME type '".$mime."' for file '".$file."' (".$mime_error.")", 'human_error' => 'Unsupported file format', "dumb_type"=>mime_type($file));
$temp = $_FILES['file']['tmp_name'];
$uploadPath = $_REQUEST['uploadpath'];
$savePath = dirname(__FILE__).'/'.$uploadPath;
if (!file_exists($savePath)) {
if(!mkdir($savePath)) {
return array(
'status' => false,
'error' => "Bad path '$savePath'",
'human_error' => 'There is a server misconfiguration preventing your file from being uploaded',
);
}
}
$file = $_FILES['file']['name'];
$exploded = explode('.', $file);
$extension = array_pop($exploded);
$fileName = md5($file.microtime_float());
$newFilePath = $fileName.'.'.$extension;
$fileWritePath = $savePath.$newFilePath;
# We want to suppress the warning on move_uploaded_file, or else
# it'll return an invalid JSON response
#error_reporting(0); # Disable this for debugging
$status = move_uploaded_file($temp, $fileWritePath);
$uploadStatus = array('status' => $status,'original_file' => $file,'wrote_file' => $newFilePath,'full_path' => getRelativePath($fileWritePath), "mime_provided"=>$mime);
return $uploadStatus;
}
}
示例8: _show_existing_object_class
function _show_existing_object_class(&$images, &$cache, &$app, $table, $id, $only_local, $id_class, $class, $descr, $e_edit_data)
{
$p =& $app->ui;
$tmp = '';
if (!isset($cache[$id_class][0])) {
return '';
}
$obj = $cache[$id_class][0];
$found_local = $obj['_table'] == $table && $obj['_id'] == $id;
if ($obj['is_local'] && $found_local == false) {
return '';
}
if ($only_local && !$found_local && substr($class, 0, 2) != 'u_') {
return '';
}
if (isset($cms_object_views[$class])) {
$objviews[$class] = array($table, $id);
}
$color = $found_local ? '#0000CC' : '#009000';
$stat = '';
if ($obj['is_public'] || $obj['is_local']) {
$stat = ' (';
if ($obj['is_public']) {
$stat .= '<FONT COLOR="RED">' . $lang['public'] . '</FONT>';
}
if ($obj['is_public'] && $obj['is_local']) {
$stat .= ', ';
}
if ($obj['is_local']) {
$stat .= $lang['local'];
}
$stat .= ')';
}
if (mime_type($obj['mime']) == 'image') {
$imagename = $obj['filename'];
if ($imagename == '') {
$imagename = $obj['mime'];
}
$images .= '<td><table border="1" cellpadding="2" cellspacing="0">' . '<tr><td align="center">' . '<a href="' . $app->url($e_edit_data);
'"><img border="0" src="' . $p->filelink('obj_data', 'data', $obj['mime'], $obj['id'], $obj['data']) . "\" alt=\"{$imagename}\"></a><br>" . '<FONT COLOR="' . $color . '">' . $descr . ", {$imagename}</FONT>{$stat}" . '</td></tr>' . '</table></td>' . "\n";
return '';
}
return '[' . $p->_looselink("<FONT COLOR=\"{$color}\">{$descr}</FONT>{$stat}", $e_edit_data) . "]\n";
}
示例9: mime_content_type
/**
* Detect MIME Content-type for a file
*
* @param string $filename Path to the tested file.
* @return string
*/
function mime_content_type($filename)
{
$ext = strtolower(array_pop(explode('.', $filename)));
if ($mime = mime_type($ext)) {
return $mime;
} elseif (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME);
$mime = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mime;
} else {
return 'application/octet-stream';
}
}
示例10: validateDataset
function validateDataset($dataPath, $projectLink, $fimsAuthCookiesAsString = null, $continue = false)
{
try {
$fimsValidateUrl = 'http://www.biscicol.org/biocode-fims/rest/validate';
# See
# http://biscicol.org/biocode-fims/rest/fims.wadl#idp1379817744
# https://fims.readthedocs.org/en/latest/amphibian_disease_example.html#validate-dataset
if ($continue == true) {
$fimsStatusUrl = $fimsValidateUrl . '/status';
$fimsContinueUrl = $fimsValidateUrl . '/continue';
$params = array('http' => array('method' => 'GET', 'header' => implode("\r\n", array('Content-type: application/x-www-form-urlencoded', 'Accept: application/json', 'User-Agent: amphibian disease portal')) . "\r\n"));
$params['http']['header'] .= "Cookie: " . $cookiesString . "\r\n";
$ctx = stream_context_create($params);
$rawResponse = file_get_contents($fimsStatusUrl, false, $ctx);
if ($rawResponse === false) {
throw new Exception("Fatal FIMS communication error 007 (No Response)");
}
$rawResponse2 = file_get_contents($fimsContinueUrl, false, $ctx);
$resp = json_decode($rawResponse, true);
$resp2 = json_decode($rawResponse2, true);
return array('status' => true, 'responses' => array('status' => $resp, 'continue' => $resp2), 'cookies' => $cookiesString);
}
# $data = smart_decode64($dataset, false);
$datasrc = decode64($dataPath);
$file = realpath($datasrc);
if (!file_exists($file)) {
return array('status' => false, 'error' => 'INVALID_FILE_PATH', 'human_error' => "Sorry, we couldn't validate your uploaded file", 'provided' => array('path' => $datasrc, 'computed_path' => $file));
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file);
finfo_close($finfo);
if (empty($mime) || $mime == 'application/zip') {
# Just the fallback that is based purely on extension
# Only used when finfo can't find a mime type
try {
include_once dirname(__FILE__) . '/helpers/js-dragdrop/manual_mime.php';
$mime = mime_type($file);
} catch (Exception $e) {
$mime_error = $e->getMessage();
$mime = null;
}
}
# https://secure.php.net/manual/en/function.curl-file-create.php
$dataUploadObj = curl_file_create($file, $mime);
# Remove the invalid "fims_extra" data
// foreach($data as $k=>$row) {
// unset($row["fimsExtra"]);
// $data[$k] = $row;
// }
# The POST object
$fimsValidateData = array('dataset' => $dataUploadObj, 'projectId' => 26, 'expeditionCode' => $projectLink);
# Login
if (empty($fimsAuthCookiesAsString)) {
global $fimsPassword;
$fimsPassCredential = $fimsPassword;
$fimsUserCredential = 'amphibiaweb';
# AmphibianDisease
$fimsAuthUrl = 'http://www.biscicol.org/biocode-fims/rest/authenticationService/login';
$fimsAuthData = array('username' => $fimsUserCredential, 'password' => $fimsPassCredential);
# Post the login
$params = array('http' => array('method' => 'POST', 'content' => http_build_query($fimsAuthData), 'header' => implode("\r\n", array('Content-type: application/x-www-form-urlencoded', 'Accept: application/json', 'User-Agent: amphibian disease portal')) . "\r\n"));
$ctx = stream_context_create($params);
$rawResponse = file_get_contents($fimsAuthUrl, false, $ctx);
if ($rawResponse === false) {
throw new Exception("Fatal FIMS communication error 008 (No Response)");
}
$loginHeaders = $http_response_header;
$cookies = array();
$cookiesString = '';
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\\s*([^;]+)/', $hdr, $matches)) {
$cookiesString .= $matches[1] . ';';
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
$loginResponse = json_decode($rawResponse, true);
if (empty($loginResponse['url'])) {
throw new Exception('Invalid Login Response E004');
}
} else {
$loginResponse = 'NO_LOGIN_CREDENTIALS_PROVIDED';
$cookiesString = $fimsAuthCookiesAsString;
$params = array('http' => array('method' => 'POST'));
}
# Post the args
$headers = array();
$headers[] = 'Content-type: multipart/form-data';
$headers[] = 'Accept: application/json';
$headers[] = 'User-Agent: amphibian disease portal';
$params = array('http' => array('method' => 'POST', 'header' => $headers, 'content' => http_build_query($fimsValidateData)));
# https://fims.readthedocs.org/en/latest/amphibian_disease_example.html#validate-dataset
$ch = curl_init($fimsValidateUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
// required as of PHP 5.6.0
# Also auto sets header to "multipart/form-data"
# Must be an array for file uploads
curl_setopt($ch, CURLOPT_POSTFIELDS, $fimsValidateData);
//.........这里部分代码省略.........
示例11: cleanSource
$src = cleanSource($src);
// last modified time (for caching)
$lastModified = filemtime($src);
// get properties
$new_width = preg_replace("/[^0-9]+/", '', get_request('w', 0));
$new_height = preg_replace("/[^0-9]+/", '', get_request('h', 0));
$zoom_crop = preg_replace("/[^0-9]+/", '', get_request('zc', 1));
$quality = preg_replace("/[^0-9]+/", '', get_request('q', 80));
$filters = get_request('f', '');
$sharpen = get_request('s', 0);
if ($new_width == 0 && $new_height == 0) {
$new_width = 100;
$new_height = 100;
}
// get mime type of src
$mime_type = mime_type($src);
// check to see if this image is in the cache already
check_cache($mime_type);
// if not in cache then clear some space and generate a new file
cleanCache();
ini_set('memory_limit', '50M');
// make sure that the src is gif/jpg/png
if (!valid_src_mime_type($mime_type)) {
displayError('Invalid src mime type: ' . $mime_type);
}
if (strlen($src) && file_exists($src)) {
// open the existing image
$image = open_image($mime_type, $src);
if ($image === false) {
displayError('Unable to open image : ' . $src);
}
示例12: stripslashes
}
}
}
if (!$err) {
// make sure we can determine mime type and extension from file name
$file_name = stripslashes($file['name']);
$file_size = $file['size'];
$file_extension = file_extension($file_name);
$mime = mime_from_path($file_name);
if (!($mime && $file_extension)) {
$err = 'Could not determine mime type or extension';
}
}
if (!$err) {
// make sure mime type is supported
$file_type = mime_type($mime);
switch ($file_type) {
case 'audio':
case 'video':
case 'image':
break;
default:
$err = 'Only audio, image and video files supported';
}
}
if (!$err) {
// make sure type and extension match
if ($type != $file_type) {
$err = 'Type ' . $file_type . ' was not the expected type ' . $type;
} else {
if ($extension != $file_extension) {
示例13: processMedia
protected function processMedia($value, $key, $thumbnail = true)
{
$image = null;
$type = null;
if (is_array($value)) {
$attributes = Kurogo::arrayVal($value, '@attributes', array());
if (!($url = Kurogo::arrayVal($attributes, 'url'))) {
return null;
}
if (!($type = Kurogo::arrayVal($attributes, 'type'))) {
if ($medium = Kurogo::arrayVal($attributes, 'medium')) {
$type = $medium;
} else {
$bits = parse_url($url);
$type = mime_type(Kurogo::arrayVal($bits, 'path'));
}
}
} elseif (is_scalar($value)) {
//assume it's a url_stat
$url = $value;
$bits = parse_url($url);
$type = mime_type(Kurogo::arrayVal($bits, 'path'));
}
if ($this->typeIsImage($type)) {
$image = new $this->imageClass();
$image->setURL($url);
$image->setThumbnail($thumbnail);
$image->init($this->initArgs);
}
return $image;
}
示例14: testMimeType
function testMimeType()
{
$this->assertEquals(mime_type('foo.tar.gz'), 'application/x-gzip');
$this->assertEquals(mime_type('foo.tar.gz', 'text/plain'), 'application/x-gzip');
$this->assertEquals(mime_type('foo.bar'), 'application/octet-stream');
$this->assertEquals(mime_type('foo.bar', 'text/plain'), 'text/plain');
$this->assertEquals(mime_type('TODO'), 'application/octet-stream');
$this->assertEquals(mime_type('TODO', 'text/plain'), 'text/plain');
}
示例15: send_file
function send_file($file, $name = null)
{
if (strpos($file, "http") === 0) {
/* HTTP link, redirect… */
header('Location:' . $file);
die("You are being redirected...");
} else {
if (strpos($file, '/plugins/files/') === 0 && @$USE_CDN) {
// use a redirect instead of an echo so that the CDN can cache the content
header('Location: http://cdn.qsapp.com' . $file);
die("You are being redirected...");
} else {
$file_path = file_root($file) . $file;
$type = mime_type($file_path);
$size = filesize($file_path);
debug("sending file \"{$file}\" ({$file_path}) with name \"{$name}\", type: {$type}, size: {$size}");
header("Content-Type: " . $type);
header("Content-Length: " . $size);
if ($name) {
header("Content-Disposition: attachment; filename=\"" . $name . "\"");
}
$contents = file_get_contents($file_path);
if (!$contents) {
return false;
}
echo $contents;
die;
}
}
return true;
}