本文整理汇总了PHP中getMimeType函数的典型用法代码示例。如果您正苦于以下问题:PHP getMimeType函数的具体用法?PHP getMimeType怎么用?PHP getMimeType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getMimeType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_edit_replay
function forum_edit_replay($id, $bid, $tid)
{
global $db;
$thread = $db->fetch_assoc('SELECT `threadID`, `bID`, `threadname`, a.boardparentID, ' . DB_PRE . 'ecp_forum_threads.closed,userID, comment, attachs,postname, adatum,
a.editcom,a.editmocom,a.rightsread, a.commentsperpost, a.moneyperpost, a.boardparentID,
a.name, a.attachments, a.attachmaxsize, a.postcom, a.attachfiles, b.rightsread as parentRead
FROM ' . DB_PRE . 'ecp_forum_threads
LEFT JOIN ' . DB_PRE . 'ecp_forum_boards AS a ON (bID = a.boardID)
LEFT JOIN ' . DB_PRE . 'ecp_forum_boards AS b ON (b.boardID = a.boardparentID)
LEFT JOIN ' . DB_PRE . 'ecp_forum_comments ON (comID = ' . $id . ')
WHERE threadID = ' . $tid . ' AND bID = ' . $bid);
if (@$_SESSION['userID'] and find_access($thread['rightsread']) and find_access($thread['parentRead']) and (find_access($thread['editcom']) and $_SESSION['userID'] == $thread['userID'] or find_access($thread['editmocom'])) and $db->errorNum() == 0) {
if (isset($_POST['comment'])) {
if ($_POST['comment'] == '' or isset($_POST['username']) and $_POST['username'] == '' or isset($_POST['title']) and $_POST['title'] == '') {
table(ERROR, NOT_NEED_ALL_INPUTS);
$tpl = new smarty();
$tpl->assign('func', 'edit');
$tpl->assign('func2', '&comID=' . $id);
$tpl->assign('comment', $_POST['comment']);
if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
$tpl->assign('title', $thread['threadname']);
}
if ($thread['userID'] == 0) {
$tpl->assign('username', $thread['postname']);
}
ob_start();
if ($thread['attachments'] and $thread['attachmaxsize']) {
$attachs = $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'mID = ' . $id . ' AND tID = ' . $tid);
if ($thread['attachments'] > $attachs) {
$rand = get_random_string(16, 2);
$tpl->assign('attach', find_access($thread['attachfiles']));
$tpl->assign('maxsize', $thread['attachmaxsize']);
$tpl->assign('rand', $rand);
$tpl->assign('sid', session_name() . '=' . session_id());
$tpl->assign('maxuploads', $thread['attachments'] - $attachs);
$tpl->assign('uploadinfo', str_replace(array('{anzahl}', '{max}'), array($thread['attachments'] - $attachs, goodsize($thread['attachmaxsize'])), FORUM_ATTACH_INFO));
$_SESSION['forum']['attach'][$bid] = $rand;
}
}
$tpl->assign('quote', true);
$tpl->display(DESIGN . '/tpl/forum/comments_add_edit' . ((UPLOAD_METHOD == 'old' and $thread['attachments'] and $thread['attachmaxsize']) ? '_old' : '') . '.html');
$content = ob_get_contents();
ob_end_clean();
main_content(FORUM_POST_EDIT, $content, '', 1);
} else {
if ($db->query(sprintf('UPDATE ' . DB_PRE . 'ecp_forum_comments SET postname = \'%s\', comment = \'%s\', edits =edits +1, editdatum = %d, edituserID = %d WHERE comID = %d', strsave(htmlspecialchars(@$_POST['username'])), strsave(comment_save($_POST['comment'])), time(), @(int) $_SESSION['userID'], $id))) {
if (find_access($thread['attachfiles'])) {
if (UPLOAD_METHOD == 'old') {
$maxattach = $thread['attachments'] - $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'bID = ' . $bid . ' AND mID = ' . $id);
foreach ($_FILES as $key => $value) {
if ($_FILES[$key] == '' or $maxattach <= 0 or $_FILES[$key]['size'] > $thread['attachmaxsize']) {
continue;
}
$mine = getMimeType($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
if ($mine == 'application/zip' or $mine == 'application/x-rar-compressed' or $mine == 'image/bmp' or $mine == 'image/gif' or $mine == 'image/jpeg' or $mine == 'image/png' or $mine == 'application/pdf' or $mine == 'text/plain' or $mine == 'text/css' or $mine == 'text/html') {
$sha1 = sha1_file($_FILES[$key]['tmp_name']);
if ($db->query(sprintf('INSERT INTO ' . DB_PRE . 'ecp_forum_attachments (`bID`, `userID`, `name`, `size`, `strname`, uploadzeit, IP, tID, mID) VALUES (%d, %d, \'%s\', %d, \'%s\', %d, \'%s\', %d, %d)', $bid, @(int) $_SESSION['userID'], strsave($_FILES[$key]['name']), (int) $_FILES[$key]['size'], $sha1, time(), $_SERVER['REMOTE_ADDR'], $tid, $id))) {
move_uploaded_file($_FILES[$key]['tmp_name'], 'uploads/forum/' . $db->last_id() . '_' . $sha1);
umask(0);
chmod('uploads/forum/' . $db->last_id() . '_' . $sha1, CHMOD);
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET anhaenge = 1 WHERE threadID = ' . $tid);
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_comments SET attachs = 1 WHERE comID = ' . $id);
}
$maxattach--;
}
}
} else {
$db->query(sprintf('UPDATE ' . DB_PRE . 'ecp_forum_attachments SET `tID` = %d, `mID` = %d WHERE validation = \'%s\' AND bID = %d', $id, $comid, strsave($_GET['rand']), $bid));
if ($db->affekt_rows()) {
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET anhaenge = 1 WHERE threadID = ' . $id);
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_comments SET attachs = 1 WHERE comID = ' . $comid);
}
}
}
if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET threadname = \'' . strsave(htmlspecialchars($_POST['title'])) . '\', vonname = \'' . strsave(htmlspecialchars(@$_POST['username'])) . '\' WHERE threadID = ' . $tid);
}
$last = $db->fetch_assoc('SELECT userID,postname,adatum, tID FROM ' . DB_PRE . 'ecp_forum_comments WHERE boardID = ' . $bid . ' ORDER BY adatum DESC LIMIT 1');
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_boards SET `lastpostuserID` = ' . (int) $last['userID'] . ', `lastpostuser` = \'' . $last['postname'] . '\', `lastpost` = ' . (int) $last['adatum'] . ', lastthreadID = ' . (int) $last['tID'] . ' WHERE (boardID = ' . $bid . ' OR boardID = ' . $thread['boardparentID'] . ')');
$last = $db->fetch_assoc('SELECT userID,postname,adatum FROM ' . DB_PRE . 'ecp_forum_comments WHERE tID = ' . $tid . ' ORDER BY adatum DESC LIMIT 1');
$db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET `lastuserID` = ' . $last['userID'] . ', `lastusername` = \'' . $last['postname'] . '\', `lastreplay` = ' . $last['adatum'] . ' WHERE threadID = ' . $tid);
unset($_SESSION['forum']['attach'][$bid]);
$anzahl = $db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND boardID =' . $bid . ' AND adatum < ' . $thread['adatum']);
header1('?section=forum&action=thread&boardID=' . $bid . '&threadID=' . $tid . '&page=' . (ceil(($anzahl - 1) / LIMIT_FORUM_COMMENTS) + 1) . '#com_' . $id);
}
}
} else {
$tpl = new smarty();
$tpl->assign('comment', htmlspecialchars($thread['comment']));
$tpl->assign('func', 'edit');
$tpl->assign('func2', '&comID=' . $id);
if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
$tpl->assign('title', $thread['threadname']);
}
if ($thread['userID'] == 0) {
$tpl->assign('username', $thread['postname']);
}
ob_start();
if ($thread['attachments'] and $thread['attachmaxsize']) {
$attachs = $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'mID = ' . $id . ' AND tID = ' . $tid);
//.........这里部分代码省略.........
示例2: array
<meta name="author" content="Brian Sandall" />
</head>
<?php
$errors = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$file = trim(filter_input(INPUT_POST, 'file'));
if (!empty($file) && is_string($file)) {
if (strpos($file, '..') !== false) {
$errors['file'] = '* Invalid file path';
} else {
$file = ltrim(rtrim($file, '\\/'), '\\/');
$filename = PATH . $file;
if (!is_file($filename)) {
$errors['file'] = '* Invalid file path or file name';
} elseif (getMimeType($filename) !== 'text/plain') {
$errors['file'] = '* Invalid file type: ' . getMimeType($filename);
}
}
} else {
$errors['file'] = '* Required field';
}
$required = array('product_code' => true, 'list_price' => true, 'sale_price' => true);
$header_labels = filter_input(INPUT_POST, 'header_labels', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
if (!is_array($header_labels)) {
$errors['header_labels']['missing'] = '* Please enter valid header labels';
} else {
foreach ($header_labels as $k => $v) {
if (empty($v) && !empty($required[$k])) {
$errors['header_labels'][$k] = '* Required field';
} elseif (!preg_match('/^[a-z0-9-_\\040]+$/i', $v)) {
$errors['header_labels'][$k] = '* Only letters, digits, spaces, hyphens, and underscores are allowed';
示例3: getPicturesData
/**
* return the content of the pictures
* @param Picture[] $pictures the list of the pictures
* @return Picture[]
*/
protected function getPicturesData(array $pictures)
{
$this->api->getPool(array_map(function (Picture $picture) {
return new Request('GET', $picture->url);
}, $pictures), ['fulfilled' => function (Response $response, $index) use($pictures) {
$pictures[$index]->content = $response->getBody()->getContents();
$pictures[$index]->mimetype = getMimeType($pictures[$index]->content);
}])->wait();
return $pictures;
}
示例4: getUrlsToBeParsed
}
# In order to not processed l10 for config.xml
# TODO And for the locales folders ?
# Get le localized resource content
$urlsToLocalizedResource = getUrlsToBeParsed($choosedLangages, $requestedURI);
$urlsToPaths = urlsToFiles($urlsToLocalizedResource, '/.*widgets/', dirname(__FILE__));
$resourceContent = getFirstFileContentFromTab($urlsToPaths);
# Debuging
//var_dump($choosedLangages);
//var_dump($requestedURI);
//var_dump($urlsToLocalizedResource);
//var_dump($urlsToPaths);
//var_dump($resourceContent);
# Send the content to the client
//header('Cache-Control: no-store, proxy-revalidate, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0');
header('Content-Type: ' . getMimeType($requestedURI));
# To avoid bug
if ($resourceContent === FALSE) {
echo 'l10n cannot resolve : ' . $requestedURI;
} else {
echo $resourceContent;
}
//--------------------- Funtions used within the process ----------------------------------
/**
* this function return the content of the first existing file in am array of file
*/
function getFirstFileContentFromTab($files)
{
$n = count($files);
for ($i = 0; $i < $n; $i++) {
$content = @file_get_contents($files[$i]);
示例5: resize_picture
if ($size[0] > GALLERY_THUMB_SIZE) {
resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_THUMB_SIZE, 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', 100, 0);
} else {
copy('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg');
umask(0);
chmod('images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', CHMOD);
}
if ($size[0] > GALLERY_PIC_SIZE) {
resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_PIC_SIZE, 'images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 100);
}
} else {
@($error .= 'Datei konnte nicht verschoben werden.(' . $_FILES[$key]['name'] . ')<br />');
}
}
} else {
@($error .= WRONG_FILE_TYPE . ' (' . $_FILES[$key]['name'] . ' : ' . getMimeType($_FILES[$key]['tmp_name'], $_FILES[$key]['name']) . ')<br />');
}
}
} else {
$error = FILE_NOT_FOUND;
}
} else {
$error = FILE_EXIST;
}
} else {
$error = 'Es wurde keine Datei hochgeladen.';
}
} else {
$error = NO_ADMIN_RIGHTS;
}
if (UPLOAD_METHOD == 'Flash') {
示例6: phpftp_view
function phpftp_view($ftp, $tempdir, $dir, $file)
{
$tmpfile = tempnam('/tmp', 'egwftp');
ftp_chdir($ftp, $dir);
$remotefile = $dir . '/' . $file;
if (!ftp_get($ftp, $tmpfile, $remotefile, FTP_BINARY)) {
echo 'tmpfile="' . $tmpfile . '",file="' . $remotefile . '"<br>' . "\n";
macro_get_Link('newlogin', 'Start over?');
$retval = 0;
} else {
$content_type = getMimeType($remotefile);
header('Content-Type: ' . $content_type);
readfile($tmpfile);
$retval = 1;
}
@unlink($tmpfile);
return $retval;
}
示例7: getMimeType
function getMimeType($filename)
{
$realpath = realpath($filename);
if ($realpath && function_exists('finfo_file') && function_exists('finfo_open') && defined('FILEINFO_MIME_TYPE')) {
// Use the Fileinfo PECL extension (PHP 5.3+)
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $realpath);
}
if (function_exists('mime_content_type')) {
// Deprecated in PHP 5.3
return mime_content_type($realpath);
}
return false;
}
/* emulate RewriteRule ^/(pics/.*|css/.*|scripts/.*|robots.txt|favicon.ico|apple-touch-icon.png)$ /$1 */
if (preg_match('@^/(pics/.*|robots.txt|favicon.ico|apple-touch-icon.png)$@', $path, $matches)) {
header('Content-Type: ' . getMimeType($matches[1]));
require $matches[1];
return;
}
if (preg_match('@^/(css/.*)$@', $path, $matches)) {
$file = $matches[1];
header('Content-Type: text/css');
require $file;
return;
}
if (preg_match('@^/(scripts/.*)$@', $path, $matches)) {
$file = $matches[1];
header('Content-Type: application/javascript');
require $file;
return;
}
示例8: die
}
} else {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
}
fclose($in);
fclose($out);
} else {
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
}
// only generate thumbs/previews if this is the last chunk
if ($chunk == $chunks - 1) {
// temp variable for uploaded file (and path)
$uploadedFile = $targetDir . DIRECTORY_SEPARATOR . $fileName;
// get MIME type
$mime = getMimeType($uploadedFile);
// get extension
$ext = pathinfo($uploadedFile, PATHINFO_EXTENSION);
// validate MIME type and extension
if (!Upload::isAllowedMime($mime) || !Upload::isAllowedExtension($ext)) {
// delete the file we just uploaded and send us back
chown($uploadedFile, 666);
unlink($uploadedFile);
die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "That file type is not allowed."}, "id" : "' . $fileName . '"}');
}
// make large thumb
// calculate resized width and height
list($orig_width, $orig_height) = @getimagesize($uploadedFile);
$scale = min(User::PICTURE_LARGE_MAX_WIDTH / $orig_width, User::PICTURE_LARGE_MAX_HEIGHT / $orig_height);
if ($scale > 1) {
$scale = 1;
示例9: getExtension
/**
* @param string $mime_type
* @return bool|string
*/
function getExtension($mime_type)
{
if (empty($mime_type)) {
return false;
}
$extensions = getMimeType(null, null, true);
$ext = array_search($mime_type, $extensions);
return $ext ? $ext : false;
}
示例10: uploadFile
function uploadFile()
{
$cachedfolder = $this->cache->isCached($this->_requestedEntry);
if ($cachedfolder === false) {
$cachedfolder = $this->getEntry($this->_requestedEntry);
if ($cachedfolder === false) {
return new WP_Error('broke', __("Root folder not found ", 'useyourdrive'));
die;
}
}
/* Check if user is allowed to upload to this dir */
if (!$cachedfolder->isInFolder($this->_rootFolder)) {
return new WP_Error('broke', __("You are not authorized to upload files to this directory", 'useyourdrive'));
die;
}
/* Upload File to server */
require 'jquery-file-upload/server/UploadHandler.php';
$accept_file_types = '/.(' . $this->options['upload_ext'] . ')$/i';
$max_file_size = $this->options['maxfilesize'];
$uploadir = wp_upload_dir();
$options = array('upload_dir' => $uploadir['path'] . '/', 'upload_url' => $uploadir['url'] . '/', 'access_control_allow_methods' => array('POST', 'PUT'), 'accept_file_types' => $accept_file_types, 'inline_file_types' => '/\\.____$/i', 'orient_image' => false, 'image_versions' => array(), 'max_file_size' => $max_file_size, 'print_response' => false);
if ($this->options['demo'] === '1') {
$options['accept_file_types'] = '/\\.____$/i';
}
$error_messages = array(1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'useyourdrive'), 2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'useyourdrive'), 3 => __('The uploaded file was only partially uploaded', 'useyourdrive'), 4 => __('No file was uploaded', 'useyourdrive'), 6 => __('Missing a temporary folder', 'useyourdrive'), 7 => __('Failed to write file to disk', 'useyourdrive'), 8 => __('A PHP extension stopped the file upload', 'useyourdrive'), 'post_max_size' => __('The uploaded file exceeds the post_max_size directive in php.ini', 'useyourdrive'), 'max_file_size' => __('File is too big', 'useyourdrive'), 'min_file_size' => __('File is too small', 'useyourdrive'), 'accept_file_types' => __('Filetype not allowed', 'useyourdrive'), 'max_number_of_files' => __('Maximum number of files exceeded', 'useyourdrive'), 'max_width' => __('Image exceeds maximum width', 'useyourdrive'), 'min_width' => __('Image requires a minimum width', 'useyourdrive'), 'max_height' => __('Image exceeds maximum height', 'useyourdrive'), 'min_height' => __('Image requires a minimum height', 'useyourdrive'));
$this->upload_handler = new UploadHandler($options, false, $error_messages);
$response = @$this->upload_handler->post(false);
/* Upload files to Google Drive */
foreach ($response['files'] as &$file) {
/* Check user permission */
$userrole = $cachedfolder->getItem()->getUserPermission()->getRole();
if (in_array($userrole, array('reader', 'commenter'))) {
$file->error = __("You are not authorized to upload files to this directory", 'useyourdrive');
}
if (!isset($file->error)) {
/* Write file */
$filePath = $file->tmp_path;
$chunkSizeBytes = 1 * 1024 * 1024;
/* Update Mime-type if needed (for IE8 and lower?) */
include_once 'mime-types/mime-types.php';
$fileExtension = pathinfo($file->name, PATHINFO_EXTENSION);
$file->type = getMimeType($fileExtension);
try {
/* Create new Google File */
$googledrive_file = new Google_Service_Drive_DriveFile();
$googledrive_file->setTitle($file->name);
$googledrive_file->setMimeType($file->type);
/* Add Parent to Google File */
if ($this->_lastFolder != null) {
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($this->_lastFolder);
$googledrive_file->setParents(array($parent));
}
/* Call the API with the media upload, defer so it doesn't immediately return. */
$this->client->setDefer(true);
$convert = $this->options['convert'] === '1' ? true : false;
$request = $this->googleDriveService->files->insert($googledrive_file, array('convert' => $convert));
$request->disableGzip();
/* Create a media file upload to represent our upload process. */
$media = new Google_Http_MediaFileUpload($this->client, $request, $file->type, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($filePath));
/* Start partialy upload
Upload the various chunks. $status will be false until the process is
complete. */
$status = false;
$handle = fopen($filePath, "rb");
while (!$status && !feof($handle)) {
set_time_limit(60);
$chunk = fread($handle, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($chunk);
}
fclose($handle);
} catch (Exception $ex) {
$file->error = __('Not uploaded to Google Drive', 'useyourdrive') . ': ' . $ex->getMessage();
}
$this->client->setDefer(false);
if (!empty($uploadStatus)) {
/* check if uploaded file has size */
$newentry = $this->googleDriveService->files->get($uploadStatus['id'], array("userIp" => $this->userip));
if ($newentry->getFileSize() === 0 && strpos($newentry->getMimeType(), 'google-apps') === false) {
$deletedentry = $this->googleDriveService->files->delete($newentry->getId(), array("userIp" => $this->userip));
$file->error = __('Not succesfully uploaded to Google Drive', 'useyourdrive');
} else {
/* Add new file to our Cache */
$cachedentry = $this->cache->addToCache($newentry);
$file->completepath = $cachedentry->getPath($this->_rootFolder);
$file->fileid = $newentry->getId();
$file->filesize = UseyourDrive_bytesToSize1024($file->size);
$file->link = urlencode($newentry->getAlternateLink());
}
}
} else {
if ($this->options['debug'] === '1') {
$file->error = __('Uploading failed', 'useyourdrive') . ': ' . $file->error;
} else {
$file->error = __('Uploading failed', 'useyourdrive');
}
}
}
/* Send email if needed */
//.........这里部分代码省略.........
示例11: encodeFileForEmail
/**
* Encode the contents of a file for emailing, including headers
*
* $file can be an array, in which case it expects these members:
* 'filename' - the filename of the file
* 'contents' - the raw binary contents of the file as a string
* and can optionally include these members:
* 'mimetype' - the mimetype of the file (calculated from filename if missing)
* 'contentLocation' - the 'Content-Location' header value for the file
*
* $file can also be a string, in which case it is assumed to be the filename
*
* h5. contentLocation
*
* Content Location is one of the two methods allowed for embedding images into an html email. It's also the simplest, and best supported
*
* Assume we have an email with this in the body:
*
* <img src="http://example.com/image.gif" />
*
* To display the image, an email viewer would have to download the image from the web every time it is displayed. Due to privacy issues, most
* viewers will not display any images unless the user clicks 'Show images in this email'. Not optimal.
*
* However, we can also include a copy of this image as an attached file in the email. By giving it a contentLocation of "http://example.com/image.gif"
* most email viewers will use this attached copy instead of downloading it. Better, most viewers will show it without a 'Show images in this email'
* conformation.
*
* Here is an example of passing this information through Email.php:
*
* $email = new Email();
* $email->attachments[] = array(
* 'filename' => BASE_PATH . "/themes/mytheme/images/header.gif",
* 'contents' => file_get_contents(BASE_PATH . "/themes/mytheme/images/header.gif"),
* 'mimetype' => 'image/gif',
* 'contentLocation' => Director::absoluteBaseURL() . "/themes/mytheme/images/header.gif"
* );
*
*/
function encodeFileForEmail($file, $destFileName = false, $disposition = NULL, $extraHeaders = "")
{
if (!$file) {
user_error("encodeFileForEmail: not passed a filename and/or data", E_USER_WARNING);
return;
}
if (is_string($file)) {
$file = array('filename' => $file);
$fh = fopen($file['filename'], "rb");
if ($fh) {
while (!feof($fh)) {
$file['contents'] .= fread($fh, 10000);
}
fclose($fh);
}
}
// Build headers, including content type
if (!$destFileName) {
$base = basename($file['filename']);
} else {
$base = $destFileName;
}
$mimeType = $file['mimetype'] ? $file['mimetype'] : getMimeType($file['filename']);
if (!$mimeType) {
$mimeType = "application/unknown";
}
if (empty($disposition)) {
$disposition = isset($file['contentLocation']) ? 'inline' : 'attachment';
}
// Encode for emailing
if (substr($file['mimetype'], 0, 4) != 'text') {
$encoding = "base64";
$file['contents'] = chunk_split(base64_encode($file['contents']));
} else {
// This mime type is needed, otherwise some clients will show it as an inline attachment
$mimeType = 'application/octet-stream';
$encoding = "quoted-printable";
$file['contents'] = QuotedPrintable_encode($file['contents']);
}
$headers = "Content-type: {$mimeType};\n\tname=\"{$base}\"\n" . "Content-Transfer-Encoding: {$encoding}\n" . "Content-Disposition: {$disposition};\n\tfilename=\"{$base}\"\n";
if (isset($file['contentLocation'])) {
$headers .= 'Content-Location: ' . $file['contentLocation'] . "\n";
}
$headers .= $extraHeaders . "\n";
// Return completed packet
return $headers . $file['contents'];
}
示例12: header
return "image/jpeg";
} else {
if ($raw_file[1] == "png") {
return "image/png";
} else {
header("HTTP/1.1 500 What Is This");
exit;
}
}
}
function drawBlankTile()
{
$image = imagecreate(256, 256);
$watercolor = imagecolorallocate($image, 29, 71, 95);
#1D475F used by frontend map.js
imagefill($image, 0, 0, $watercolor);
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
}
$config =& get_config();
$map_tile = getRequestedTileName();
$map_dir = !empty($config['map_path']) ? $config['map_path'] : BASEPATH . 'map/';
$filename = $map_dir . "/{$map_tile}";
if (file_exists($filename)) {
$mime_type = getMimeType($map_tile);
header("Content-Type: {$mime_type}");
readfile($filename);
} else {
drawBlankTile();
}
示例13: saveToDatabase
public static function saveToDatabase($originalName = null, $storedName = null, $itemType = null, $itemID = null, $projectID = null)
{
// all but projectID required
if ($originalName == null || $storedName == null || $itemType == null || $itemID == null) {
return null;
}
// get extension
$ext = pathinfo($originalName, PATHINFO_EXTENSION);
$storedName .= '.' . $ext;
// temp variable for absolute path
$absPath = UPLOAD_PATH . '/' . $storedName;
// get file size
$size = filesize($absPath);
// get mime type
$mime = getMimeType($absPath);
// get height and width (if image)
$imgSize = getimagesize($absPath);
if ($imgSize) {
$height = $imgSize[1];
$width = $imgSize[0];
} else {
$height = null;
$width = null;
}
// store in db
$upload = new Upload(array('creator_id' => Session::getUserID(), 'original_name' => $originalName, 'stored_name' => $storedName, 'mime' => $mime, 'size' => $size, 'height' => $height, 'width' => $width, 'item_type' => $itemType, 'item_id' => $itemID, 'project_id' => $projectID));
$upload->save();
return $upload->getID();
}
示例14: substr_replace
$fullLink = $href;
} else {
if (substr($href, 0, 1) === "/") {
$path = substr_replace($_POST["url"], "", $_POST["url"] . length - 1, 1);
$fullLink = $path . $href;
}
}
// Attempt to visit page
if ($file = @fopen($fullLink, "r")) {
$page = "Available!";
fclose($file);
} else {
$page = "Unknown!";
}
// Formatting
echo "<tr>\n <td>" . $link->nodeValue . "</td>\n <td>" . $fullLink . "</td>;\n <td>" . getMimeType(pathinfo($href, PATHINFO_EXTENSION)) . "</td>\n <td>" . $page . "</td>\n </tr>";
$linkCount++;
}
echo "</table>";
if ($linkCount > 0) {
echo $linkCount, " Links found!";
} else {
echo "No links found! <br> Empty/Non-Existent page!";
}
function getMimeType($file)
{
// MIME types array - Courtesy of Phill Pafford from StackOverflow
$mimeTypes = array("323" => "text/h323", "acx" => "application/internet-property-stream", "ai" => "application/postscript", "aif" => "audio/x-aiff", "aifc" => "audio/x-aiff", "aiff" => "audio/x-aiff", "asf" => "video/x-ms-asf", "asr" => "video/x-ms-asf", "asx" => "video/x-ms-asf", "au" => "audio/basic", "avi" => "video/x-msvideo", "axs" => "application/olescript", "bas" => "text/plain", "bcpio" => "application/x-bcpio", "bin" => "application/octet-stream", "bmp" => "image/bmp", "c" => "text/plain", "cat" => "application/vnd.ms-pkiseccat", "cdf" => "application/x-cdf", "cer" => "application/x-x509-ca-cert", "class" => "application/octet-stream", "clp" => "application/x-msclip", "cmx" => "image/x-cmx", "cod" => "image/cis-cod", "cpio" => "application/x-cpio", "crd" => "application/x-mscardfile", "crl" => "application/pkix-crl", "crt" => "application/x-x509-ca-cert", "csh" => "application/x-csh", "css" => "text/css", "dcr" => "application/x-director", "der" => "application/x-x509-ca-cert", "dir" => "application/x-director", "dll" => "application/x-msdownload", "dms" => "application/octet-stream", "doc" => "application/msword", "dot" => "application/msword", "dvi" => "application/x-dvi", "dxr" => "application/x-director", "eps" => "application/postscript", "etx" => "text/x-setext", "evy" => "application/envoy", "exe" => "application/octet-stream", "fif" => "application/fractals", "flr" => "x-world/x-vrml", "gif" => "image/gif", "gtar" => "application/x-gtar", "gz" => "application/x-gzip", "h" => "text/plain", "hdf" => "application/x-hdf", "hlp" => "application/winhlp", "hqx" => "application/mac-binhex40", "hta" => "application/hta", "htc" => "text/x-component", "htm" => "text/html", "html" => "text/html", "htt" => "text/webviewhtml", "ico" => "image/x-icon", "ief" => "image/ief", "iii" => "application/x-iphone", "ins" => "application/x-internet-signup", "isp" => "application/x-internet-signup", "jfif" => "image/pipeg", "jpe" => "image/jpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "js" => "application/x-javascript", "latex" => "application/x-latex", "lha" => "application/octet-stream", "lsf" => "video/x-la-asf", "lsx" => "video/x-la-asf", "lzh" => "application/octet-stream", "m13" => "application/x-msmediaview", "m14" => "application/x-msmediaview", "m3u" => "audio/x-mpegurl", "man" => "application/x-troff-man", "mdb" => "application/x-msaccess", "me" => "application/x-troff-me", "mht" => "message/rfc822", "mhtml" => "message/rfc822", "mid" => "audio/mid", "mny" => "application/x-msmoney", "mov" => "video/quicktime", "movie" => "video/x-sgi-movie", "mp2" => "video/mpeg", "mp3" => "audio/mpeg", "mpa" => "video/mpeg", "mpe" => "video/mpeg", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpp" => "application/vnd.ms-project", "mpv2" => "video/mpeg", "ms" => "application/x-troff-ms", "mvb" => "application/x-msmediaview", "nws" => "message/rfc822", "oda" => "application/oda", "p10" => "application/pkcs10", "p12" => "application/x-pkcs12", "p7b" => "application/x-pkcs7-certificates", "p7c" => "application/x-pkcs7-mime", "p7m" => "application/x-pkcs7-mime", "p7r" => "application/x-pkcs7-certreqresp", "p7s" => "application/x-pkcs7-signature", "pbm" => "image/x-portable-bitmap", "pdf" => "application/pdf", "pfx" => "application/x-pkcs12", "pgm" => "image/x-portable-graymap", "pko" => "application/ynd.ms-pkipko", "pma" => "application/x-perfmon", "pmc" => "application/x-perfmon", "pml" => "application/x-perfmon", "pmr" => "application/x-perfmon", "pmw" => "application/x-perfmon", "pnm" => "image/x-portable-anymap", "pot" => "application/vnd.ms-powerpoint", "ppm" => "image/x-portable-pixmap", "pps" => "application/vnd.ms-powerpoint", "ppt" => "application/vnd.ms-powerpoint", "prf" => "application/pics-rules", "ps" => "application/postscript", "pub" => "application/x-mspublisher", "qt" => "video/quicktime", "ra" => "audio/x-pn-realaudio", "ram" => "audio/x-pn-realaudio", "ras" => "image/x-cmu-raster", "rgb" => "image/x-rgb", "rmi" => "audio/mid", "roff" => "application/x-troff", "rtf" => "application/rtf", "rtx" => "text/richtext", "scd" => "application/x-msschedule", "sct" => "text/scriptlet", "setpay" => "application/set-payment-initiation", "setreg" => "application/set-registration-initiation", "sh" => "application/x-sh", "shar" => "application/x-shar", "sit" => "application/x-stuffit", "snd" => "audio/basic", "spc" => "application/x-pkcs7-certificates", "spl" => "application/futuresplash", "src" => "application/x-wais-source", "sst" => "application/vnd.ms-pkicertstore", "stl" => "application/vnd.ms-pkistl", "stm" => "text/html", "svg" => "image/svg+xml", "sv4cpio" => "application/x-sv4cpio", "sv4crc" => "application/x-sv4crc", "t" => "application/x-troff", "tar" => "application/x-tar", "tcl" => "application/x-tcl", "tex" => "application/x-tex", "texi" => "application/x-texinfo", "texinfo" => "application/x-texinfo", "tgz" => "application/x-compressed", "tif" => "image/tiff", "tiff" => "image/tiff", "tr" => "application/x-troff", "trm" => "application/x-msterminal", "tsv" => "text/tab-separated-values", "txt" => "text/plain", "uls" => "text/iuls", "ustar" => "application/x-ustar", "vcf" => "text/x-vcard", "vrml" => "x-world/x-vrml", "wav" => "audio/x-wav", "wcm" => "application/vnd.ms-works", "wdb" => "application/vnd.ms-works", "wks" => "application/vnd.ms-works", "wmf" => "application/x-msmetafile", "wps" => "application/vnd.ms-works", "wri" => "application/x-mswrite", "wrl" => "x-world/x-vrml", "wrz" => "x-world/x-vrml", "xaf" => "x-world/x-vrml", "xbm" => "image/x-xbitmap", "xla" => "application/vnd.ms-excel", "xlc" => "application/vnd.ms-excel", "xlm" => "application/vnd.ms-excel", "xls" => "application/vnd.ms-excel", "xlsx" => "vnd.ms-excel", "xlt" => "application/vnd.ms-excel", "xlw" => "application/vnd.ms-excel", "xof" => "x-world/x-vrml", "xpm" => "image/x-xpixmap", "xwd" => "image/x-xwindowdump", "z" => "application/x-compress", "zip" => "application/zip");
// Get values after the "." (example."txt")
$extension = end(explode('.', $file));
// If unmatched or no "."
示例15: formatoImg
function formatoImg($img)
{
$mime = getMimeType($img);
if (strpos("@" . $mime, "jpeg")) {
return "jpg";
}
if (strpos("@" . $mime, "gif")) {
return "gif";
}
if (strpos("@" . $mime, "png")) {
return "png";
}
if (strpos("@" . $mime, "bmp")) {
return "bmp";
}
if (file_exists($img)) {
$fp = fopen($img, "r");
}
if ($fp) {
$cabec = fread($fp, 10);
if (strpos("@" . $cabec, "JFIF")) {
return "jpg";
}
if (strpos("@" . $cabec, "GIF89")) {
return "gif";
}
if (strpos("@" . $cabec, "PNG")) {
return "png";
}
if (strpos("@" . $cabec, "BM")) {
return "bmp";
}
}
return "jpg";
}