当前位置: 首页>>代码示例>>PHP>>正文


PHP stored_file::get_mimetype方法代码示例

本文整理汇总了PHP中stored_file::get_mimetype方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::get_mimetype方法的具体用法?PHP stored_file::get_mimetype怎么用?PHP stored_file::get_mimetype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stored_file的用法示例。


在下文中一共展示了stored_file::get_mimetype方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: can_import_file

 /**
  * Check if the given file is capable of being imported by this plugin.
  * As {@link file_storage::mimetype()} now uses finfo PHP extension if available,
  * the value returned by $file->get_mimetype for a .dat file is not the same on all servers.
  * So we must made 2 checks to verify if the plugin can import the file.
  * @param stored_file $file the file to check
  * @return bool whether this plugin can import the file
  */
 public function can_import_file($file) {
     $mimetypes = array(
         mimeinfo('type', '.dat'),
         mimeinfo('type', '.zip')
     );
     return in_array($file->get_mimetype(), $mimetypes) || in_array(mimeinfo('type', $file->get_filename()), $mimetypes);
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:15,代码来源:formatbase.php

示例2: create_file_preview

 /**
  * Generates a preview image for the stored file
  *
  * @param stored_file $file the file we want to preview
  * @param string $mode preview mode, eg. 'thumb'
  * @return stored_file|bool the newly created preview file or false
  */
 protected function create_file_preview(stored_file $file, $mode)
 {
     $mimetype = $file->get_mimetype();
     if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
         // make a preview of the image
         $data = $this->create_imagefile_preview($file, $mode);
     } else {
         // unable to create the preview of this mimetype yet
         return false;
     }
     if (empty($data)) {
         return false;
     }
     $context = context_system::instance();
     $record = array('contextid' => $context->id, 'component' => 'core', 'filearea' => 'preview', 'itemid' => 0, 'filepath' => '/' . trim($mode, '/') . '/', 'filename' => $file->get_contenthash());
     $imageinfo = getimagesizefromstring($data);
     if ($imageinfo) {
         $record['mimetype'] = $imageinfo['mime'];
     }
     return $this->create_file_from_string($record, $data);
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:28,代码来源:file_storage.php

示例3: can_import_file

 /**
  * Check if the given file is capable of being imported by this plugin.
  *
  * Note that expensive or detailed integrity checks on the file should
  * not be performed by this method. Simple file type or magic-number tests
  * would be suitable.
  *
  * @param stored_file $file the file to check
  * @return bool whether this plugin can import the file
  */
 public function can_import_file($file)
 {
     return $file->get_mimetype() == $this->mime_type();
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:14,代码来源:format.php

示例4: set_format_by_file

 /**
  * if we already know we have exactly one file,
  * bypass set_formats and just pass the file
  * so we can detect the formats by mimetype.
  *
  * @param stored_file $file         file to set the format from
  * @param mixed       $extraformats any additional formats other than by mimetype
  *                                  eg leap2a etc
  */
 public function set_format_by_file(stored_file $file, $extraformats = null)
 {
     $this->file = $file;
     $fileformat = portfolio_format_from_mimetype($file->get_mimetype());
     if (is_string($extraformats)) {
         $extraformats = array($extraformats);
     } else {
         if (!is_array($extraformats)) {
             $extraformats = array();
         }
     }
     $this->set_formats(array_merge(array($fileformat), $extraformats));
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:22,代码来源:portfoliolib.php

示例5: portfolio_format_from_file

/**
* Deduce export format from file mimetype
*
* This function returns the revelant portfolio export format
* which is used to determine which portfolio plugins can be used
* for exporting this content
* according to the mime type of the given file
* this only works when exporting exactly <b>one</b> file
*
* @param stored_file $file file to check mime type for
*
* @return string the format constant (see PORTFOLIO_FORMAT_XXX constants)
*/
function portfolio_format_from_file(stored_file $file)
{
    static $alreadymatched;
    if (empty($alreadymatched)) {
        $alreadymatched = array();
    }
    if (!$file instanceof stored_file) {
        throw new portfolio_exception('invalidfileargument', 'portfolio');
    }
    $mimetype = $file->get_mimetype();
    if (array_key_exists($mimetype, $alreadymatched)) {
        return $alreadymatched[$mimetype];
    }
    $allformats = portfolio_supported_formats();
    foreach ($allformats as $format => $classname) {
        $supportedmimetypes = call_user_func(array($classname, 'mimetypes'));
        if (!is_array($supportedmimetypes)) {
            debugging("one of the portfolio format classes, {$classname}, said it supported something funny for mimetypes, should have been array...");
            debugging(print_r($supportedmimetypes, true));
            continue;
        }
        if (in_array($mimetype, $supportedmimetypes)) {
            $alreadymatched[$mimetype] = $format;
            return $format;
        }
    }
    return PORTFOLIO_FORMAT_FILE;
    // base case for files...
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:42,代码来源:portfoliolib.php

示例6: file_is_indexable

 /**
  * Checks to see if a passed file is indexable.
  *
  * @param \stored_file $file The file to check
  * @return bool True if the file can be indexed
  */
 protected function file_is_indexable($file)
 {
     if (!empty($this->config->maxindexfilekb) && $file->get_filesize() > $this->config->maxindexfilekb * 1024) {
         // The file is too big to index.
         return false;
     }
     $mime = $file->get_mimetype();
     if ($mime == 'application/vnd.moodle.backup') {
         // We don't index Moodle backup files. There is nothing usefully indexable in them.
         return false;
     }
     return true;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:19,代码来源:engine.php

示例7: label_generate_resized_image

/**
 * Resize the image, if required, then generate an img tag and, if required, a link to the full-size image
 * @param stored_file $file the image file to process
 * @param int $maxwidth the maximum width allowed for the image
 * @param int $maxheight the maximum height allowed for the image
 * @return string HTML fragment to add to the label
 */
function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight)
{
    global $CFG;
    $fullurl = moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename());
    $link = null;
    $attrib = array('alt' => $file->get_filename(), 'src' => $fullurl);
    if ($imginfo = $file->get_imageinfo()) {
        // Work out the new width / height, bounded by maxwidth / maxheight
        $width = $imginfo['width'];
        $height = $imginfo['height'];
        if (!empty($maxwidth) && $width > $maxwidth) {
            $height *= (double) $maxwidth / $width;
            $width = $maxwidth;
        }
        if (!empty($maxheight) && $height > $maxheight) {
            $width *= (double) $maxheight / $height;
            $height = $maxheight;
        }
        $attrib['width'] = $width;
        $attrib['height'] = $height;
        // If the size has changed and the image is of a suitable mime type, generate a smaller version
        if ($width != $imginfo['width']) {
            $mimetype = $file->get_mimetype();
            if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
                require_once $CFG->libdir . '/gdlib.php';
                $tmproot = make_temp_directory('mod_label');
                $tmpfilepath = $tmproot . '/' . $file->get_contenthash();
                $file->copy_content_to($tmpfilepath);
                $data = generate_image_thumbnail($tmpfilepath, $width, $height);
                unlink($tmpfilepath);
                if (!empty($data)) {
                    $fs = get_file_storage();
                    $record = array('contextid' => $file->get_contextid(), 'component' => $file->get_component(), 'filearea' => $file->get_filearea(), 'itemid' => $file->get_itemid(), 'filepath' => '/', 'filename' => 's_' . $file->get_filename());
                    $smallfile = $fs->create_file_from_string($record, $data);
                    // Replace the image 'src' with the resized file and link to the original
                    $attrib['src'] = moodle_url::make_draftfile_url($smallfile->get_itemid(), $smallfile->get_filepath(), $smallfile->get_filename());
                    $link = $fullurl;
                }
            }
        }
    } else {
        // Assume this is an image type that get_imageinfo cannot handle (e.g. SVG)
        $attrib['width'] = $maxwidth;
    }
    $img = html_writer::empty_tag('img', $attrib);
    if ($link) {
        return html_writer::link($link, $img);
    } else {
        return $img;
    }
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:58,代码来源:lib.php

示例8: create_file_preview

 /**
  * Generates a preview image for the stored file
  *
  * @param stored_file $file the file we want to preview
  * @param string $mode preview mode, eg. 'thumb'
  * @return stored_file|bool the newly created preview file or false
  */
 protected function create_file_preview(stored_file $file, $mode)
 {
     $mimetype = $file->get_mimetype();
     if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
         // make a preview of the image
         $data = $this->create_imagefile_preview($file, $mode);
     } else {
         // unable to create the preview of this mimetype yet
         return false;
     }
     if (empty($data)) {
         return false;
     }
     // getimagesizefromstring() is available from PHP 5.4 but we need to support
     // lower versions, so...
     $tmproot = make_temp_directory('thumbnails');
     $tmpfilepath = $tmproot . '/' . $file->get_contenthash() . '_' . $mode;
     file_put_contents($tmpfilepath, $data);
     $imageinfo = getimagesize($tmpfilepath);
     unlink($tmpfilepath);
     $context = context_system::instance();
     $record = array('contextid' => $context->id, 'component' => 'core', 'filearea' => 'preview', 'itemid' => 0, 'filepath' => '/' . trim($mode, '/') . '/', 'filename' => $file->get_contenthash());
     if ($imageinfo) {
         $record['mimetype'] = $imageinfo['mime'];
     }
     return $this->create_file_from_string($record, $data);
 }
开发者ID:nigeli,项目名称:moodle,代码行数:34,代码来源:file_storage.php

示例9: make_tag

 /**
  * Create portfolio tag
  *
  * @param stored_file $file file information object
  * @param string $path file path
  * @param array $attributes portfolio attributes
  * @return string
  */
 public static function make_tag($file, $path, $attributes)
 {
     $srcattr = 'href';
     $tag = 'a';
     $content = $file->get_filename();
     if (in_array($file->get_mimetype(), portfolio_format_image::mimetypes())) {
         $srcattr = 'src';
         $tag = 'img';
         $content = '';
     }
     $attributes[$srcattr] = $path;
     // this will override anything we might have been passed (which is good)
     $dom = new DomDocument();
     $elem = null;
     if ($content) {
         $elem = $dom->createElement($tag, $content);
     } else {
         $elem = $dom->createElement($tag);
     }
     foreach ($attributes as $key => $value) {
         $elem->setAttribute($key, $value);
     }
     $dom->appendChild($elem);
     return $dom->saveXML($elem);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:33,代码来源:formats.php

示例10: send_stored_file

/**
 * Handles the sending of file data to the user's browser, including support for
 * byteranges etc.
 *
 * @category files
 * @global stdClass $CFG
 * @global stdClass $COURSE
 * @global moodle_session $SESSION
 * @param stored_file $stored_file local file object
 * @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
 * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
 * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
 * @param string $filename Override filename
 * @param bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
 *                        if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
 *                        you must detect this case when control is returned using connection_aborted. Please not that session is closed
 *                        and should not be reopened.
 * @return null script execution stopped unless $dontdie is true
 */
function send_stored_file($stored_file, $lifetime = 86400, $filter = 0, $forcedownload = false, $filename = null, $dontdie = false)
{
    global $CFG, $COURSE, $SESSION;
    if (!$stored_file or $stored_file->is_directory()) {
        // nothing to serve
        if ($dontdie) {
            return;
        }
        die;
    }
    if ($dontdie) {
        ignore_user_abort(true);
    }
    session_get_instance()->write_close();
    // unlock session during fileserving
    // Use given MIME type if specified, otherwise guess it using mimeinfo.
    // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
    // only Firefox saves all files locally before opening when content-disposition: attachment stated
    $filename = is_null($filename) ? $stored_file->get_filename() : $filename;
    $isFF = check_browser_version('Firefox', '1.5');
    // only FF > 1.5 properly tested
    $mimetype = ($forcedownload and !$isFF) ? 'application/x-forcedownload' : ($stored_file->get_mimetype() ? $stored_file->get_mimetype() : mimeinfo('type', $filename));
    $lastmodified = $stored_file->get_timemodified();
    $filesize = $stored_file->get_filesize();
    if ($lifetime > 0 && !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        // get unixtime of request header; clip extra junk off first
        $since = strtotime(preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"]));
        if ($since && $since >= $lastmodified) {
            header('HTTP/1.1 304 Not Modified');
            header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
            header('Cache-Control: max-age=' . $lifetime);
            header('Content-Type: ' . $mimetype);
            if ($dontdie) {
                return;
            }
            die;
        }
    }
    //do not put '@' before the next header to detect incorrect moodle configurations,
    //error should be better than "weird" empty lines for admins/users
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT');
    // if user is using IE, urlencode the filename so that multibyte file name will show up correctly on popup
    if (check_browser_version('MSIE')) {
        $filename = rawurlencode($filename);
    }
    if ($forcedownload) {
        header('Content-Disposition: attachment; filename="' . $filename . '"');
    } else {
        header('Content-Disposition: inline; filename="' . $filename . '"');
    }
    if ($lifetime > 0) {
        header('Cache-Control: max-age=' . $lifetime);
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
        header('Pragma: ');
        if (empty($CFG->disablebyteserving) && $mimetype != 'text/plain' && $mimetype != 'text/html') {
            header('Accept-Ranges: bytes');
            if (!empty($_SERVER['HTTP_RANGE']) && strpos($_SERVER['HTTP_RANGE'], 'bytes=') !== FALSE) {
                // byteserving stuff - for acrobat reader and download accelerators
                // see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
                // inspired by: http://www.coneural.org/florian/papers/04_byteserving.php
                $ranges = false;
                if (preg_match_all('/(\\d*)-(\\d*)/', $_SERVER['HTTP_RANGE'], $ranges, PREG_SET_ORDER)) {
                    foreach ($ranges as $key => $value) {
                        if ($ranges[$key][1] == '') {
                            //suffix case
                            $ranges[$key][1] = $filesize - $ranges[$key][2];
                            $ranges[$key][2] = $filesize - 1;
                        } else {
                            if ($ranges[$key][2] == '' || $ranges[$key][2] > $filesize - 1) {
                                //fix range length
                                $ranges[$key][2] = $filesize - 1;
                            }
                        }
                        if ($ranges[$key][2] != '' && $ranges[$key][2] < $ranges[$key][1]) {
                            //invalid byte-range ==> ignore header
                            $ranges = false;
                            break;
                        }
                        //prepare multipart header
                        $ranges[$key][0] = "\r\n--" . BYTESERVING_BOUNDARY . "\r\nContent-Type: {$mimetype}\r\n";
                        $ranges[$key][0] .= "Content-Range: bytes {$ranges[$key][1]}-{$ranges[$key][2]}/{$filesize}\r\n\r\n";
//.........这里部分代码省略.........
开发者ID:raymondAntonio,项目名称:moodle,代码行数:101,代码来源:filelib.php


注:本文中的stored_file::get_mimetype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。