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


PHP mimeinfo_from_type函数代码示例

本文整理汇总了PHP中mimeinfo_from_type函数的典型用法代码示例。如果您正苦于以下问题:PHP mimeinfo_from_type函数的具体用法?PHP mimeinfo_from_type怎么用?PHP mimeinfo_from_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: folder_get_file_link

/**
 * Returns file link
 * @param object $file
 * @param object $folder
 * @param object $context
 * @return string html link
 */
function folder_get_file_link($file, $folder, $context)
{
    global $CFG;
    $strfile = get_string('file');
    $strdownload = get_string('download');
    $icon = mimeinfo_from_type("icon", $file->get_mimetype());
    $urlbase = "{$CFG->wwwroot}/pluginfile.php";
    $path = '/' . $context->id . '/folder_content/' . $folder->revision . $file->get_filepath() . $file->get_filename();
    $viewurl = file_encode_url($urlbase, $path, false);
    $downloadurl = file_encode_url($urlbase, $path, true);
    $downloadurl = "&nbsp;<a href=\"{$downloadurl}\" title=\"" . get_string('downloadfile') . "\"><img src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strdownload}\" /></a>";
    return "<a href=\"{$viewurl}\" title=\"\"><img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . s($file->get_filename()) . '</a>' . $downloadurl;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:20,代码来源:locallib.php

示例2: print_student_answer

 function print_student_answer($userid, $return = false)
 {
     global $CFG, $USER;
     $fs = get_file_storage();
     $browser = get_file_browser();
     $output = '';
     if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $found = true;
             $mimetype = $file->get_mimetype();
             $icon = mimeinfo_from_type('icon', $mimetype);
             $path = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/assignment_submission/' . $userid . '/' . $filename);
             $output .= '<a href="' . $path . '" ><img class="icon" src="' . $CFG->pixpath . '/f/' . $icon . '" alt="' . $icon . '" />' . s($filename) . '</a><br />';
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     return $output;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:19,代码来源:assignment.class.php

示例3: displaydir

function displaydir($file_info)
{
    global $CFG;
    $children = $file_info->get_children();
    $parent_info = $file_info->get_parent();
    $strname = get_string('name');
    $strsize = get_string('size');
    $strmodified = get_string('modified');
    $strfolder = get_string('folder');
    $strfile = get_string('file');
    $strdownload = get_string('download');
    $strdelete = get_string('delete');
    $straction = get_string('action');
    $path = array();
    $params = $file_info->get_params_rawencoded();
    $params = implode('&amp;', $params);
    $path[] = $file_info->get_visible_name();
    $level = $parent_info;
    while ($level) {
        $params = $level->get_params_rawencoded();
        $params = implode('&amp;', $params);
        $path[] = '<a href="index.php?' . $params . '">' . $level->get_visible_name() . '</a>';
        $level = $level->get_parent();
    }
    $path = array_reverse($path);
    $path = implode(' / ', $path);
    echo $path . ' /';
    echo "<div>";
    echo "<hr/>";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"740\" class=\"files\">";
    echo "<tr>";
    echo "<th class=\"header\" scope=\"col\"></th>";
    echo "<th class=\"header name\" scope=\"col\">{$strname}</th>";
    echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>";
    echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>";
    echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>";
    echo "</tr>\n";
    $parentwritable = $file_info->is_writable();
    if ($parent_info) {
        $params = $parent_info->get_params_rawencoded();
        $params = implode('&amp;', $params);
        echo "<tr class=\"folder\">";
        print_cell();
        print_cell('left', '<a href="index.php?' . $params . '"><img src="' . $CFG->pixpath . '/f/parent.gif" class="icon" alt="" />&nbsp;' . get_string('parentfolder') . '</a>', 'name');
        print_cell();
        print_cell();
        print_cell();
        echo "</tr>";
    }
    if ($children) {
        foreach ($children as $child_info) {
            $filename = $child_info->get_visible_name();
            $filesize = $child_info->get_filesize();
            $filesize = $filesize ? display_size($filesize) : '';
            $filedate = $child_info->get_timemodified();
            $filedate = $filedate ? userdate($filedate) : '';
            $mimetype = $child_info->get_mimetype();
            $params = $child_info->get_params_rawencoded();
            $params = implode('&amp;', $params);
            if ($child_info->is_directory()) {
                echo "<tr class=\"folder\">";
                print_cell();
                print_cell("left", "<a href=\"index.php?{$params}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"{$strfolder}\" />&nbsp;" . s($filename) . "</a>", 'name');
                print_cell("right", $filesize, 'size');
                print_cell("right", $filedate, 'date');
                if ($parentwritable) {
                    print_cell("right", "<a href=\"index.php?{$params}&amp;sesskey=" . sesskey() . "&amp;delete=1\"><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command');
                } else {
                    print_cell();
                }
                echo "</tr>";
            } else {
                $icon = mimeinfo_from_type("icon", $mimetype);
                if ($downloadurl = $child_info->get_url(true)) {
                    $downloadurl = "&nbsp;<a href=\"{$downloadurl}\" title=\"" . get_string('downloadfile') . "\"><img src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strdownload}\" /></a>";
                } else {
                    $downloadurl = '';
                }
                if ($viewurl = $child_info->get_url()) {
                    $viewurl = "&nbsp;" . link_to_popup_window($viewurl, "display", "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strfile}\" />&nbsp;", 480, 640, get_string('viewfileinpopup'), null, true);
                } else {
                    $viewurl = '';
                }
                echo "<tr class=\"file\">";
                print_cell();
                print_cell("left", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . s($filename) . $downloadurl . $viewurl, 'name');
                print_cell("right", $filesize, 'size');
                print_cell("right", $filedate, 'date');
                if ($parentwritable) {
                    print_cell("right", "<a href=\"index.php?{$params}&amp;sesskey=" . sesskey() . "&amp;delete=1\"><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command');
                } else {
                    print_cell();
                }
                echo "</tr>";
            }
        }
    }
    echo "</table>";
    echo "</div>";
    echo "<hr/>";
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:index.php

示例4: _get_draftfiles

 function _get_draftfiles($draftid, $suffix)
 {
     global $USER, $CFG;
     $html = '';
     if (!($context = get_context_instance(CONTEXT_USER, $USER->id))) {
     }
     $contextid = $context->id;
     $filearea = 'user_draft';
     $browser = get_file_browser();
     $fs = get_file_storage();
     $filepath = '/';
     if (!($directory = $fs->get_file($context->id, 'user_draft', $draftid, $filepath, '.'))) {
         $directory = new virtual_root_file($context->id, 'user_draft', $draftid);
         $filepath = $directory->get_filepath();
     }
     $files = $fs->get_directory_files($context->id, 'user_draft', $draftid, $directory->get_filepath());
     $parent = $directory->get_parent_directory();
     $html .= '<ul class="file-list" id="draftfiles-' . $suffix . '">';
     foreach ($files as $file) {
         $filename = $file->get_filename();
         $filenameurl = rawurlencode($filename);
         $filepath = $file->get_filepath();
         $filesize = $file->get_filesize();
         $filesize = $filesize ? display_size($filesize) : '';
         $mimetype = $file->get_mimetype();
         $icon = mimeinfo_from_type('icon', $mimetype);
         $viewurl = $browser->encodepath("{$CFG->wwwroot}/draftfile.php", "/{$contextid}/user_draft/{$draftid}" . $filepath . $filename, false, false);
         $html .= '<li>';
         $html .= "<a href=\"{$viewurl}\"><img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" />&nbsp;" . s($filename) . " ({$filesize})</a> ";
         $html .= "<a href=\"###\" onclick='rm_{$suffix}(" . $file->get_itemid() . ", \"" . $filename . "\", this)'><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" /></a>";
         $html .= '</li>';
     }
     $html .= '</ul>';
     return $html;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:35,代码来源:filemanager.php

示例5: toHtml

 function toHtml()
 {
     global $CFG, $OUTPUT;
     $htmltable = new html_table();
     $htmltable->head = array(get_string('deleteupload', 'wiki'), get_string('uploadname', 'wiki'), get_string('uploadactions', 'wiki'));
     $fs = get_file_storage();
     $files = $fs->get_area_files($this->_fileinfo['contextid'], 'mod_wiki', 'attachments', $this->_fileinfo['itemid']);
     //TODO: verify where this is coming from, all params must be validated (skodak)
     if (count($files) < 2) {
         return get_string('noattachments', 'wiki');
     }
     //get tags
     foreach (array('image', 'attach', 'link') as $tag) {
         $tags[$tag] = wiki_parser_get_token($this->_format, $tag);
     }
     foreach ($files as $file) {
         if (!$file->is_directory()) {
             $checkbox = '<input type="checkbox" name="' . $this->_attributes['name'] . '[]" value="' . $file->get_pathnamehash() . '"';
             if (in_array($file->get_pathnamehash(), $this->_value)) {
                 $checkbox .= ' checked="checked"';
             }
             $checkbox .= " />";
             //actions
             $icon = mimeinfo_from_type('icon', $file->get_mimetype());
             $file_url = file_encode_url($CFG->wwwroot . '/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/" . $file->get_filename());
             $action_icons = "";
             if (!empty($tags['attach'])) {
                 $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" " . $this->printInsertTags($tags['attach'], $file->get_filename()) . " title=\"" . get_string('attachmentattach', 'wiki') . "\"><img src=\"" . $OUTPUT->pix_url('f/pdf')->out() . "\" alt=\"Attach\" /></a>";
                 //TODO: localize
             }
             $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" " . $this->printInsertTags($tags['link'], $file_url) . " title=\"" . get_string('attachmentlink', 'wiki') . "\"><img src=\"" . $OUTPUT->pix_url('f/web')->out() . "\" alt=\"Link\" /></a>";
             if ($icon == 'image') {
                 $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" " . $this->printInsertTags($tags['image'], $file->get_filename()) . " title=\"" . get_string('attachmentimage', 'wiki') . "\"><img src=\"" . $OUTPUT->pix_url('f/image')->out() . "\" alt=\"Image\" /></a>";
                 //TODO: localize
             }
             $htmltable->data[] = array($checkbox, '<a href="' . $file_url . '">' . $file->get_filename() . '</a>', $action_icons);
         }
     }
     return html_writer::table($htmltable);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:40,代码来源:wikifiletable.php

示例6: file_mimetype_icon

/**
 * Returns the relative icon path for a given mime type
 *
 * This function should be used in conjuction with $OUTPUT->old_icon_url to produce
 * a return the full path to an icon.
 *
 * <code>
 * $mimetype = 'image/jpg';
 * $icon = $OUTPUT->old_icon_url(file_mimetype_icon($mimetype));
 * echo '<img src="'.$icon.'" alt="'.$mimetype.'" />';
 * </code>
 *
 * @todo When an $OUTPUT->icon method is available this function should be altered
 * to conform with that.
 *
 * @param string $mimetype The mimetype to fetch an icon for
 * @param int $size The size of the icon. Not yet implemented
 * @return string The relative path to the icon
 */
function file_mimetype_icon($mimetype, $size = null)
{
    $icon = mimeinfo_from_type('icon', $mimetype);
    $icon = substr($icon, 0, strrpos($icon, '.'));
    if ($size != null && is_int($size)) {
        $icon .= '-' . $size;
    }
    return 'f/' . $icon;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:28,代码来源:filelib.php

示例7: display_browse_field

 function display_browse_field($recordid, $template)
 {
     global $CFG, $DB;
     if (!($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         return '';
     }
     if (empty($content->content)) {
         return '';
     }
     $browser = get_file_browser();
     if (!($file = $this->get_file($recordid, $content))) {
         return '';
     }
     $name = empty($content->content1) ? $file->get_filename() : $content->content1;
     $icon = mimeinfo_from_type('icon', $file->get_mimetype());
     $src = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/data_content/' . $content->id . '/' . $file->get_filename());
     $width = $this->field->param1 ? ' width  = "' . s($this->field->param1) . '" ' : ' ';
     $height = $this->field->param2 ? ' height = "' . s($this->field->param2) . '" ' : ' ';
     $str = '<img src="' . $CFG->pixpath . '/f/' . $icon . '" height="16" width="16" alt="' . $icon . '" />&nbsp;' . '<a href="' . $src . '" >' . s($name) . '</a>';
     return $str;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:21,代码来源:field.class.php

示例8: get_mimetype_description

/**
 * Obtains descriptions for file types (e.g. 'Microsoft Word document') from the
 * mimetypes.php language file.
 *
 * @param mixed $obj - instance of stored_file or file_info or array/stdClass with field
 *   'filename' and 'mimetype', or just a string with mimetype (though it is recommended to
 *   have filename); In case of array/stdClass the field 'mimetype' is optional.
 * @param bool $capitalise If true, capitalises first character of result
 * @return string Text description
 */
function get_mimetype_description($obj, $capitalise = false)
{
    $filename = $mimetype = '';
    if (is_object($obj) && method_exists($obj, 'get_filename') && method_exists($obj, 'get_mimetype')) {
        // this is an instance of stored_file
        $mimetype = $obj->get_mimetype();
        $filename = $obj->get_filename();
    } else {
        if (is_object($obj) && method_exists($obj, 'get_visible_name') && method_exists($obj, 'get_mimetype')) {
            // this is an instance of file_info
            $mimetype = $obj->get_mimetype();
            $filename = $obj->get_visible_name();
        } else {
            if (is_array($obj) || is_object($obj)) {
                $obj = (array) $obj;
                if (!empty($obj['filename'])) {
                    $filename = $obj['filename'];
                }
                if (!empty($obj['mimetype'])) {
                    $mimetype = $obj['mimetype'];
                }
            } else {
                $mimetype = $obj;
            }
        }
    }
    $mimetypefromext = mimeinfo('type', $filename);
    if (empty($mimetype) || $mimetypefromext !== 'document/unknown') {
        // if file has a known extension, overwrite the specified mimetype
        $mimetype = $mimetypefromext;
    }
    $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    if (empty($extension)) {
        $mimetypestr = mimeinfo_from_type('string', $mimetype);
        $extension = str_replace('.', '', mimeinfo_from_type('extension', $mimetype));
    } else {
        $mimetypestr = mimeinfo('string', $filename);
    }
    $chunks = explode('/', $mimetype, 2);
    $chunks[] = '';
    $attr = array('mimetype' => $mimetype, 'ext' => $extension, 'mimetype1' => $chunks[0], 'mimetype2' => $chunks[1]);
    $a = array();
    foreach ($attr as $key => $value) {
        $a[$key] = $value;
        $a[strtoupper($key)] = strtoupper($value);
        $a[ucfirst($key)] = ucfirst($value);
    }
    // MIME types may include + symbol but this is not permitted in string ids.
    $safemimetype = str_replace('+', '_', $mimetype);
    $safemimetypestr = str_replace('+', '_', $mimetypestr);
    $customdescription = mimeinfo('customdescription', $filename);
    if ($customdescription) {
        // Call format_string on the custom description so that multilang
        // filter can be used (if enabled on system context). We use system
        // context because it is possible that the page context might not have
        // been defined yet.
        $result = format_string($customdescription, true, array('context' => context_system::instance()));
    } else {
        if (get_string_manager()->string_exists($safemimetype, 'mimetypes')) {
            $result = get_string($safemimetype, 'mimetypes', (object) $a);
        } else {
            if (get_string_manager()->string_exists($safemimetypestr, 'mimetypes')) {
                $result = get_string($safemimetypestr, 'mimetypes', (object) $a);
            } else {
                if (get_string_manager()->string_exists('default', 'mimetypes')) {
                    $result = get_string('default', 'mimetypes', (object) $a);
                } else {
                    $result = $mimetype;
                }
            }
        }
    }
    if ($capitalise) {
        $result = ucfirst($result);
    }
    return $result;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:87,代码来源:filelib.php

示例9: mimetype

 /**
  * Return mimetype by given file pathname
  *
  * If file has a known extension, we return the mimetype based on extension.
  * Otherwise (when possible) we try to get the mimetype from file contents.
  *
  * @param string $pathname full path to the file
  * @param string $filename correct file name with extension, if omitted will be taken from $path
  * @return string
  */
 public static function mimetype($pathname, $filename = null)
 {
     if (empty($filename)) {
         $filename = $pathname;
     }
     $type = mimeinfo('type', $filename);
     if ($type === 'document/unknown' && class_exists('finfo') && file_exists($pathname)) {
         $finfo = new finfo(FILEINFO_MIME_TYPE);
         $type = mimeinfo_from_type('type', $finfo->file($pathname));
     }
     return $type;
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:22,代码来源:file_storage.php

示例10: _get_draftfiles

 function _get_draftfiles($draftid, $suffix)
 {
     global $USER, $OUTPUT, $CFG;
     $context = get_context_instance(CONTEXT_USER, $USER->id);
     $fs = get_file_storage();
     $html = '<ul class="file-list" id="draftfiles-' . $suffix . '">';
     if ($files = $fs->get_directory_files($context->id, 'user_draft', $draftid, '/', true)) {
         foreach ($files as $file) {
             if ($file->is_directory()) {
                 continue;
             }
             $filename = $file->get_filename();
             $filepath = $file->get_filepath();
             $fullname = ltrim($filepath . $filename, '/');
             $filesize = $file->get_filesize();
             $filesize = $filesize ? display_size($filesize) : '';
             $icon = mimeinfo_from_type('icon', $file->get_mimetype());
             $icon = str_replace('.gif', '', $icon);
             //TODO: temp icon fix
             $viewurl = file_encode_url("{$CFG->wwwroot}/draftfile.php", "/{$context->id}/user_draft/{$draftid}/" . $fullname, false, false);
             $html .= '<li>';
             $html .= "<a href=\"{$viewurl}\"><img src=\"" . $OUTPUT->old_icon_url('f/' . $icon) . "\" class=\"icon\" />&nbsp;" . s($fullname) . " ({$filesize})</a> ";
             // TODO: maybe better use file->id here - but then make 100% it is from my own draftfiles ;-)
             //       anyway this does not work for subdirectories
             $html .= "<a href=\"###\" onclick='rm_file(" . $file->get_itemid() . ", \"" . addslashes_js($fullname) . "\", this)'><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" /></a>";
             $html .= '</li>';
         }
     }
     $html .= '</ul>';
     return $html;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:filemanager.php

示例11: mimetype

 /**
  * Return mimetype by given file pathname
  *
  * This method uses fileinfo module to get mimetype using magic bytes if file exists.
  * If not, it will get mimetype based on filename
  *
  * @param string $pathname
  * @return string
  */
 public static function mimetype($pathname)
 {
     if (file_exists($pathname)) {
         $finfo = new finfo(FILEINFO_MIME_TYPE);
         return mimeinfo_from_type('type', $finfo->file($pathname));
     } else {
         return mimeinfo('type', $pathname);
     }
 }
开发者ID:nmicha,项目名称:moodle,代码行数:18,代码来源:file_storage.php

示例12: rawurlencode

    $filenameurl = rawurlencode($filename);
    $filepath = $file->get_filepath();
    $filesize = $file->get_filesize();
    $filesize = $filesize ? display_size($filesize) : '';
    $mimetype = $file->get_mimetype();
    if ($file->is_directory()) {
        if ($subdirs) {
            $dirname = explode('/', trim($filepath, '/'));
            $dirname = array_pop($dirname);
            echo '<div class="folder">';
            echo "<a href=\"draftfiles.php?itemid={$itemid}&amp;filepath={$filepath}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"{$strfolder}\" />&nbsp;" . s($dirname) . "</a> ";
            echo "<a href=\"draftfiles.php?itemid={$itemid}&amp;filepath={$filepath}&amp;delete={$filenameurl}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}\"><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>";
            echo '</div>';
        }
    } else {
        $icon = mimeinfo_from_type('icon', $mimetype);
        $viewurl = $browser->encodepath("{$CFG->wwwroot}/draftfile.php", "/{$contextid}/user_draft/{$itemid}" . $filepath . $filename, false, false);
        echo '<div class="file">';
        echo "<a href=\"{$viewurl}\"><img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . s($filename) . " ({$filesize})</a> ";
        echo "<a href=\"draftfiles.php?itemid={$itemid}&amp;filepath={$filepath}&amp;delete={$filenameurl}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}\"><img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>";
        echo '</div>';
    }
}
echo '</div>';
if ($maxbytes == 0 or $maxbytes > $totalbytes) {
    echo '<form enctype="multipart/form-data" method="post" action="draftfiles.php"><div>';
    if ($maxbytes) {
        echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxbytes - $totalbytes) . '" />';
    }
    echo '<input type="hidden" name="itemid" value="' . $itemid . '" />';
    echo '<input type="hidden" name="filepath" value="' . s($filepath) . '" />';
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:draftfiles.php

示例13: blog_print_attachments

/**
 * if return=html, then return a html string.
 * if return=text, then return a text-only string.
 * otherwise, print HTML for non-images, and return image HTML
 */
function blog_print_attachments($blogentry, $return = NULL)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $fs = get_file_storage();
    $browser = get_file_browser();
    $files = $fs->get_area_files(SYSCONTEXTID, 'blog', $blogentry->id);
    $imagereturn = "";
    $output = "";
    $strattachment = get_string("attachment", "forum");
    foreach ($files as $file) {
        if ($file->is_directory()) {
            continue;
        }
        $filename = $file->get_filename();
        $ffurl = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . SYSCONTEXTID . '/blog/' . $blogentry->id . '/' . $filename);
        $type = $file->get_mimetype();
        $icon = mimeinfo_from_type("icon", $type);
        $type = mimeinfo_from_type("type", $type);
        $image = "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"\" />";
        if ($return == "html") {
            $output .= "<a href=\"{$ffurl}\">{$image}</a> ";
            $output .= "<a href=\"{$ffurl}\">{$filename}</a><br />";
        } else {
            if ($return == "text") {
                $output .= "{$strattachment} {$filename}:\n{$ffurl}\n";
            } else {
                if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                    // Image attachments don't get printed as links
                    $imagereturn .= "<br /><img src=\"{$ffurl}\" alt=\"\" />";
                } else {
                    echo "<a href=\"{$ffurl}\">{$image}</a> ";
                    echo filter_text("<a href=\"{$ffurl}\">{$filename}</a><br />");
                }
            }
        }
    }
    if ($return) {
        return $output;
    }
    return $imagereturn;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:47,代码来源:lib.php

示例14: glossary_print_attachments

/**
 * if return=html, then return a html string.
 * if return=text, then return a text-only string.
 * otherwise, print HTML for non-images, and return image HTML
 *     if attachment is an image, $align set its aligment.
 * @param object $entry
 * @param object $cm
 * @param string $type html, txt, empty
 * @param string $align left or right
 * @return image string or nothing depending on $type param
 */
function glossary_print_attachments($entry, $cm, $type = NULL, $align = "left")
{
    global $CFG, $DB;
    if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) {
        return '';
    }
    if ($entry->sourceglossaryid == $cm->instance) {
        if (!($maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid))) {
            return '';
        }
        $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
    } else {
        $filecontext = $context;
    }
    $strattachment = get_string('attachment', 'glossary');
    $fs = get_file_storage();
    $browser = get_file_browser();
    $imagereturn = '';
    $output = '';
    if ($files = $fs->get_area_files($filecontext->id, 'glossary_attachment', $entry->id, "timemodified", false)) {
        foreach ($files as $file) {
            $filename = $file->get_filename();
            $mimetype = $file->get_mimetype();
            $icon = mimeinfo_from_type('icon', $mimetype);
            $iconimage = '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />';
            $path = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/glossary_attachment/' . $entry->id . '/' . $filename);
            if ($type == 'html') {
                $output .= "<a href=\"{$path}\">{$iconimage}</a> ";
                $output .= "<a href=\"{$path}\">" . s($filename) . "</a>";
                $output .= "<br />";
            } else {
                if ($type == 'text') {
                    $output .= "{$strattachment} " . s($filename) . ":\n{$path}\n";
                } else {
                    if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) {
                        // Image attachments don't get printed as links
                        $imagereturn .= "<br /><img src=\"{$path}\" alt=\"\" />";
                    } else {
                        $output .= "<a href=\"{$path}\">{$iconimage}</a> ";
                        $output .= filter_text("<a href=\"{$path}\">" . s($filename) . "</a>");
                        $output .= '<br />';
                    }
                }
            }
        }
    }
    if ($type) {
        return $output;
    } else {
        echo $output;
        return $imagereturn;
    }
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:64,代码来源:lib.php

示例15: get_mimetype_description

/**
 * Obtains descriptions for file types (e.g. 'Microsoft Word document') from the
 * mimetypes.php language file.
 *
 * @param mixed $obj - instance of stored_file or file_info or array/stdClass with field
 *   'filename' and 'mimetype', or just a string with mimetype (though it is recommended to
 *   have filename); In case of array/stdClass the field 'mimetype' is optional.
 * @param bool $capitalise If true, capitalises first character of result
 * @return string Text description
 */
function get_mimetype_description($obj, $capitalise = false)
{
    $filename = $mimetype = '';
    if (is_object($obj) && method_exists($obj, 'get_filename') && method_exists($obj, 'get_mimetype')) {
        // this is an instance of stored_file
        $mimetype = $obj->get_mimetype();
        $filename = $obj->get_filename();
    } else {
        if (is_object($obj) && method_exists($obj, 'get_visible_name') && method_exists($obj, 'get_mimetype')) {
            // this is an instance of file_info
            $mimetype = $obj->get_mimetype();
            $filename = $obj->get_visible_name();
        } else {
            if (is_array($obj) || is_object($obj)) {
                $obj = (array) $obj;
                if (!empty($obj['filename'])) {
                    $filename = $obj['filename'];
                }
                if (!empty($obj['mimetype'])) {
                    $mimetype = $obj['mimetype'];
                }
            } else {
                $mimetype = $obj;
            }
        }
    }
    $mimetypefromext = mimeinfo('type', $filename);
    if (empty($mimetype) || $mimetypefromext !== 'document/unknown') {
        // if file has a known extension, overwrite the specified mimetype
        $mimetype = $mimetypefromext;
    }
    $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    if (empty($extension)) {
        $mimetypestr = mimeinfo_from_type('string', $mimetype);
        $extension = str_replace('.', '', mimeinfo_from_type('extension', $mimetype));
    } else {
        $mimetypestr = mimeinfo('string', $filename);
    }
    $chunks = explode('/', $mimetype, 2);
    $chunks[] = '';
    $attr = array('mimetype' => $mimetype, 'ext' => $extension, 'mimetype1' => $chunks[0], 'mimetype2' => $chunks[1]);
    $a = array();
    foreach ($attr as $key => $value) {
        $a[$key] = $value;
        $a[strtoupper($key)] = strtoupper($value);
        $a[ucfirst($key)] = ucfirst($value);
    }
    if (get_string_manager()->string_exists($mimetype, 'mimetypes')) {
        $result = get_string($mimetype, 'mimetypes', (object) $a);
    } else {
        if (get_string_manager()->string_exists($mimetypestr, 'mimetypes')) {
            $result = get_string($mimetypestr, 'mimetypes', (object) $a);
        } else {
            if (get_string_manager()->string_exists('default', 'mimetypes')) {
                $result = get_string('default', 'mimetypes', (object) $a);
            } else {
                $result = $mimetype;
            }
        }
    }
    if ($capitalise) {
        $result = ucfirst($result);
    }
    return $result;
}
开发者ID:JP-Git,项目名称:moodle,代码行数:75,代码来源:filelib.php


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