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


PHP mimeinfo函数代码示例

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


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

示例1: render_files_tree_viewer

 public function render_files_tree_viewer(files_tree_viewer $tree)
 {
     $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
     $html .= $this->output->container_start('coursefilesbreadcrumb');
     foreach ($tree->path as $path) {
         $html .= $path;
         $html .= ' / ';
     }
     $html .= $this->output->container_end();
     $html .= $this->output->box_start();
     $table = new html_table();
     $table->head = array(get_string('filename', 'backup'), get_string('size'), get_string('modified'));
     $table->align = array('left', 'right', 'right');
     $table->width = '100%';
     $table->data = array();
     foreach ($tree->tree as $file) {
         if (!empty($file['isdir'])) {
             $table->data[] = array(html_writer::link($file['url'], $this->output->pix_icon('f/folder', 'icon') . ' ' . $file['filename']), '', $file['filedate']);
         } else {
             $table->data[] = array(html_writer::link($file['url'], $this->output->pix_icon('f/' . mimeinfo('icon', $file['filename']), get_string('icon')) . ' ' . $file['filename']), $file['filesize'], $file['filedate']);
         }
     }
     $html .= html_writer::table($table);
     $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid' => $tree->context->id)), get_string('coursefilesedit'), 'get');
     $html .= $this->output->box_end();
     return $html;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:27,代码来源:renderer.php

示例2: htmllize_tree

 /**
  * Internal function - creates htmls structure suitable for YUI tree.
  */
 protected function htmllize_tree($tree, $dir)
 {
     global $CFG;
     $yuiconfig = array();
     $yuiconfig['type'] = 'html';
     if (empty($dir['subdirs']) and empty($dir['files'])) {
         return '';
     }
     $result = '<ul>';
     foreach ($dir['subdirs'] as $subdir) {
         $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . $this->htmllize_tree($tree, $subdir) . '</li>';
     }
     foreach ($dir['files'] as $file) {
         $url = file_encode_url("{$CFG->wwwroot}/blocks/csv_enrol/getfile.php", '/' . $tree->context->id . '/user/csvenrol' . $file->get_filepath() . $file->get_filename(), true);
         $filename = $file->get_filename();
         $icon = mimeinfo("icon", $filename);
         if (strlen($filename) > 10) {
             $pi = pathinfo($filename);
             $txt = $pi['filename'];
             $ext = $pi['extension'];
             $filename = substr($filename, 0, 14) . '...' . $ext;
         }
         $image = $this->output->pix_icon("f/{$icon}", $filename, 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . html_writer::link($url, $image . '&nbsp;' . $filename) . '</div></li>';
     }
     $result .= '</ul>';
     return $result;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:32,代码来源:renderer.php

示例3: get_listing

 public function get_listing($path = '', $page = '')
 {
     global $CFG;
     $list = array();
     $list['list'] = array();
     // the management interface url
     $list['manage'] = false;
     // dynamically loading
     $list['dynload'] = true;
     // the current path of this list.
     // set to true, the login link will be removed
     $list['nologin'] = true;
     // set to true, the search button will be removed
     $list['nosearch'] = true;
     $tree = array();
     if (empty($path)) {
         $buckets = $this->s->listBuckets();
         foreach ($buckets as $bucket) {
             $folder = array('title' => $bucket, 'children' => array(), 'thumbnail' => $CFG->pixpath . '/f/folder-32.png', 'path' => $bucket);
             $tree[] = $folder;
         }
     } else {
         $contents = $this->s->getBucket($path);
         foreach ($contents as $file) {
             $info = $this->s->getObjectInfo($path, baseName($file['name']));
             $tree[] = array('title' => $file['name'], 'size' => $file['size'], 'date' => userdate($file['time']), 'source' => $path . '/' . $file['name'], 'thumbnail' => $CFG->pixpath . '/f/' . mimeinfo('icon32', $file['name']));
         }
     }
     $list['list'] = $tree;
     return $list;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:repository.class.php

示例4: get_student_answer

/**
 * Returns the HTML to display the file submitted by the student
 * (adapted from mod/assignment/lib.php)
 *
 * @param int $attemptid attempt id
 * @param int $questionid question id
 * @return string string to print to display file list
 */
function get_student_answer($attemptid, $questionid)
{
    global $CFG;
    $filearea = quiz_file_area_name($attemptid, $questionid);
    $output = '';
    if ($basedir = quiz_file_area($filearea)) {
        if ($files = get_directory_list($basedir)) {
            if (count($files) == 0) {
                return false;
            }
            foreach ($files as $key => $file) {
                require_once $CFG->libdir . '/filelib.php';
                $icon = mimeinfo('icon', $file);
                // remove "questionattempt", the first dir in the path, from the URL
                $filearealist = explode('/', $filearea);
                $fileareaurl = implode('/', array_slice($filearealist, 1));
                if ($CFG->slasharguments) {
                    $ffurl = "{$CFG->wwwroot}/question/file.php/{$fileareaurl}/{$file}";
                } else {
                    $ffurl = "{$CFG->wwwroot}/question/file.php?file=/{$fileareaurl}/{$file}";
                }
                $output .= '<img align="middle" src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a><br />';
            }
        }
    }
    // (Is this desired for theme reasons?)
    //$output = '<div class="files">'.$output.'</div>';
    return $output;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:37,代码来源:locallib.php

示例5: block_exabis_eportfolio_print_extern_item

function block_exabis_eportfolio_print_extern_item($item, $access)
{
    global $CFG;
    print_heading(format_string($item->name));
    $box_content = '';
    if ($item->type == 'link') {
        $link = clean_param($item->url, PARAM_URL);
        $link_js = str_replace('http://', '', $link);
        if ($link) {
            $box_content .= '<p><a href="#" onclick="window.open(\'http://' . addslashes_js($link_js) . '\',\'validate\',\'width=620,height=450,scrollbars=yes,status=yes,resizable=yes,menubar=yes,location=yes\');return true;">' . $link . '</a></p>';
        }
    } elseif ($item->type == 'file') {
        if ($item->attachment) {
            $type = mimeinfo("type", $item->attachment);
            $ffurl = "{$CFG->wwwroot}/blocks/exabis_eportfolio/portfoliofile.php?access=" . $access . "&itemid=" . $item->id;
            if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                // Image attachments don't get printed as links
                $box_content .= "<img width=\"100%\" src=\"{$ffurl}\" alt=\"" . format_string($item->name) . "\" /><br/>";
            } else {
                $box_content .= "<p>" . link_to_popup_window("{$ffurl}", 'popup', "{$ffurl}", $height = 400, $width = 500, format_string($item->name), 'none', true) . "</p>";
            }
        }
    }
    $box_content .= format_text($item->intro, FORMAT_HTML);
    print_box($box_content);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:26,代码来源:externlib.php

示例6: htmllize_tree

    /**
     * Internal function - creates htmls structure suitable for YUI tree.
     */
    protected function htmllize_tree($tree, $dir) {
        global $CFG;
        $yuiconfig = array();
        $yuiconfig['type'] = 'html';

        if (empty($dir['subdirs']) and empty($dir['files'])) {
            return '';
        }

        $result = '<ul>';
        foreach ($dir['subdirs'] as $subdir) {
            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
        }

        foreach ($dir['files'] as $file) {
            $filename = $file->get_filename();
            $icon = mimeinfo("icon", $filename);
            if ($CFG->enableplagiarism) {
                require_once($CFG->libdir.'/plagiarismlib.php');
                $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
            } else {
                $plagiarsmlinks = '';
            }
            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
        }

        $result .= '</ul>';

        return $result;
    }
开发者ID:numbas,项目名称:moodle,代码行数:35,代码来源:renderer.php

示例7: definition

 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     //--------------------------------------------------------------------------------
     $urls = $this->_customdata['urls'];
     $fromareaname = $this->_customdata['fromareaname'];
     $toareaname = $this->_customdata['toareaname'];
     $fileoptions = array(QUESTION_FILEDONOTHING => get_string('donothing', 'question'), QUESTION_FILECOPY => get_string('copy', 'question', $fromareaname), QUESTION_FILEMOVE => get_string('move', 'question', $fromareaname), QUESTION_FILEMOVELINKSONLY => get_string('movelinksonly', 'question', $fromareaname));
     $brokenfileoptions = array(QUESTION_FILEDONOTHING => get_string('donothing', 'question'), QUESTION_FILEMOVELINKSONLY => get_string('movelinksonly', 'question', $fromareaname));
     $brokenurls = $this->_customdata['brokenurls'];
     if (count($urls)) {
         $mform->addElement('header', 'general', get_string('filestomove', 'question', $toareaname));
         $i = 0;
         foreach (array_keys($urls) as $url) {
             $iconname = mimeinfo('icon', $url);
             $icontype = mimeinfo('type', $url);
             $img = "<img src=\"{$CFG->pixpath}/f/{$iconname}\"  class=\"icon\" alt=\"{$icontype}\" />";
             if (in_array($url, $brokenurls)) {
                 $mform->addElement('select', "urls[{$i}]", $img . $url, $brokenfileoptions);
             } else {
                 $mform->addElement('select', "urls[{$i}]", $img . $url, $fileoptions);
             }
             $i++;
         }
     }
     if (count($brokenurls)) {
         $mform->addElement('advcheckbox', 'ignorebroken', get_string('ignorebroken', 'question'));
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons(true, get_string('movecategory', 'question'));
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:32,代码来源:contextmove_form.php

示例8: definition

 function definition()
 {
     global $CFG;
     global $COURSE;
     $mform =& $this->_form;
     //-- General --------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     /// name
     $mform->addElement('text', 'name', get_string('name'), array('size' => '60'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     /// text (description)
     $mform->addElement('htmleditor', 'text', get_string('description'));
     $mform->setType('text', PARAM_RAW);
     //$mform->addRule('text', get_string('required'), 'required', null, 'client');
     $mform->setHelpButton('text', array('writing', 'richtext'), false, 'editorhelpbutton');
     /// introformat
     $mform->addElement('format', 'introformat', get_string('format'));
     //-- Stamp Collection------------------------------------------------------------
     $mform->addElement('header', 'stampcollection', get_string('modulename', 'stampcoll'));
     /// stampimage
     make_upload_directory("{$COURSE->id}");
     // Just in case
     $images = array();
     $coursefiles = get_directory_list("{$CFG->dataroot}/{$COURSE->id}", $CFG->moddata);
     foreach ($coursefiles as $filename) {
         if (mimeinfo("icon", $filename) == "image.gif") {
             $images["{$filename}"] = $filename;
         }
     }
     $mform->addElement('select', 'image', get_string('stampimage', 'stampcoll'), array_merge(array('' => get_string('default')), $images), 'a', 'b', 'c', 'd');
     $mform->addElement('static', 'stampimageinfo', '', get_string('stampimageinfo', 'stampcoll'));
     /// displayzero
     $mform->addElement('selectyesno', 'displayzero', get_string('displayzero', 'stampcoll'));
     $mform->setDefault('displayzero', 0);
     //-------------------------------------------------------------------------------
     // add standard elements, common to all modules
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // add standard buttons, common to all modules
     $this->add_action_buttons();
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:42,代码来源:mod_form.php

示例9: print_student_answer

 function print_student_answer($userid, $return = false)
 {
     global $CFG, $USER;
     $filearea = $this->file_area_name($userid);
     $output = '';
     if ($basedir = $this->file_area($userid)) {
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}");
                 //died right here
                 //require_once($ffurl);
                 $output = '<img align="middle" src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a><br />';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     return $output;
 }
开发者ID:veritech,项目名称:pare-project,代码行数:20,代码来源:assignment.class.php

示例10: print_user_files

 /**
  * Produces a list of links to the files uploaded by a user
  *
  * @param $userid int optional id of the user. If 0 then $USER->id is used.
  * @param $return boolean optional defaults to false. If true the list is returned rather than printed
  * @return string optional
  */
 function print_user_files($userid = 0, $return = false)
 {
     global $CFG, $USER;
     if (!$userid) {
         if (!isloggedin()) {
             return '';
         }
         $userid = $USER->id;
     }
     $filearea = $this->file_area_name($userid);
     $output = '';
     if ($basedir = $this->file_area($userid)) {
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                 // Syntax Highlighert source code
                 $viewlink = link_to_popup_window('/mod/assignment/type/onlinejudge/source.php?id=' . $this->cm->id . '&amp;userid=' . $userid . '&amp;file=' . $file, $file . 'sourcecode', get_string('preview'), 500, 740, $file, 'none', true, 'button' . $userid);
                 $output .= '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a> (' . $viewlink . ')<br />';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
开发者ID:hit-moodle,项目名称:onlinejudge,代码行数:36,代码来源:assignment.class.php

示例11: photogallery_folder_view

function photogallery_folder_view($folder)
{
    global $CFG, $metatags, $messages;
    require_once $CFG->dirroot . 'lib/filelib.php';
    $metatags .= file_get_contents($CFG->dirroot . "mod/photogallery/css");
    $metatags .= <<<END
        <script type="text/javascript">
            var elggWwwRoot = "{$CFG->wwwroot}";
        </script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/prototype.js"></script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/scriptaculous.js?load=effects"></script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/lightbox.js"></script>
        <link rel="stylesheet" href="{$CFG->wwwroot}mod/photogallery/lightbox/css/lightbox.css" type="text/css" media="screen" />

END;
    $file_html = "";
    $photo_html = "";
    $folder_html = "";
    // Get all the files in this folder
    if ($files = get_records_select('files', "folder = ? AND files_owner = ? ORDER BY time_uploaded desc", array($folder->ident, $folder->files_owner))) {
        foreach ($files as $file) {
            if (run("users:access_level_check", $file->access) == true) {
                $image = $CFG->wwwroot . "_files/icon.php?id=" . $file->ident . "&amp;w=200&amp;h=200";
                $filepath = $CFG->wwwroot . user_info("username", $file->files_owner) . "/files/{$folder->ident}/{$file->ident}/" . urlencode($file->originalname);
                $image = "<a href=\"{$CFG->wwwroot}_files/icon.php?id={$file->ident}&w=500&h=500\" rel=\"lightbox[folder]\"><img src=\"{$image}\" /></a>";
                $fileinfo = round($file->size / 1048576, 4) . "Mb";
                $filelinks = file_edit_links($file);
                $uploaded = sprintf(__gettext("Uploaded on %s"), strftime("%A, %d %B %Y", $file->time_uploaded));
                $keywords = display_output_field(array("", "keywords", "file", "file", $file->ident, $file->owner));
                $mimetype = mimeinfo('type', $file->originalname);
                if (empty($file->title)) {
                    $file->title = __gettext("No title");
                }
                if (substr_count($mimetype, "image") > 0) {
                    $photo_html .= <<<END

                            <div class="photogallery-photo-container">
                                <div class="photogallery-photo-image">
                                    {$image}
                                </div>
                                <div class="photogallery-photo-info">
                                    <h2 class="photogallery-photo-title"><a href="{$filepath}" >{$file->title}</a></h2>
                                    <p class="photogallery-photo-description">
                                        {$file->description}
                                    </p>
                                    <p class="photogallery-photo-keywords">
                                        {$keywords}
                                    </p>
                                    <p class="photogallery-photo-infobar">
                                        {$uploaded}<br />
                                        {$fileinfo} {$mimetype} {$filelinks}
                                    </p>
                                </div>
                            </div>

END;
                } else {
                    $file_html .= <<<END

                            <div class="photogallery-file-container">
                                <div class="photogallery-file-image">
                                    <a href="{$filepath}">{$image}</a>
                                </div>
                                <div class="photogallery-file-info">
                                    <h2 class="photogallery-file-title"><a href="{$filepath}">{$file->title}</a></h2>
                                    <p>{$file->description}</p>
                                    <p class="photogallery-file-keywords">
                                        {$keywords}
                                    </p>
                                    <p class="photogallery-file-infobar">
                                        {$uploaded}<br />
                                        {$fileinfo} {$mimetype} {$filelinks}
                                    </p>
                                </div>
                            </div>

END;
                }
            }
        }
    }
    if ($subfolders = get_records_select('file_folders', "parent = ? AND files_owner = ? ORDER BY name desc", array($folder->ident, $folder->owner))) {
        foreach ($subfolders as $subfolder) {
            $folderlinks = file_folder_edit_links($subfolder);
            $keywords = display_output_field(array("", "keywords", "folder", "folder", $subfolder->ident, $subfolder->owner));
            $filepath = $CFG->wwwroot . user_info("username", $folder->files_owner) . "/files/" . $subfolder->ident;
            $folder_html .= <<<END

                        <div class="photogallery-file-container">
                            <div class="photogallery-file-image">
                                <a href="{$filepath}"><img src="{$CFG->wwwroot}_files/folder.png" /></a>
                            </div>
                            <div class="photogallery-file-info">
                                <h2 class="photogallery-file-title"><a href="{$filepath}">{$subfolder->name}</a></h2>
                                <p class="photogallery-file-keywords">
                                    {$keywords}
                                </p>
                                <p class="photogallery-file-infobar">
                                    {$folderlinks}
                                </p>
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:tulipan-svn,代码行数:101,代码来源:lib.php

示例12: required_param

require_once $CFG->libdir . '/filelib.php';
$id = required_param('id', PARAM_INT);
// Course Module ID
$printclose = optional_param('printclose', 0, PARAM_INT);
if (!($cm = get_coursemodule_from_id('lesson', $id))) {
    error('Course Module ID was incorrect');
}
if (!($course = get_record('course', 'id', $cm->course))) {
    error('Course is misconfigured');
}
if (!($lesson = get_record('lesson', 'id', $cm->instance))) {
    error('Course module is incorrect');
}
require_login($course->id, false, $cm);
// Get the mimetype
$mimetype = mimeinfo("type", $lesson->mediafile);
if (!is_url($lesson->mediafile) and !in_array($mimetype, array('text/plain', 'text/html'))) {
    print_header($course->shortname);
}
if ($printclose) {
    // this is for framesets
    if ($lesson->mediaclose) {
        print_header($course->shortname);
        echo '<div class="lessonmediafilecontrol">
                <form>
                <div>
                <input type="button" onclick="top.close();" value="' . get_string("closewindow") . '" />
                </div>
                </form>
                </div>';
        print_footer();
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:mediafile.php

示例13: add_file

 public function add_file($section, $name, $path, $display = 0)
 {
     global $DB, $CFG, $USER;
     $section = (int) $section;
     $display = (int) $display;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/mod/resource/lib.php';
     require_once $CFG->dirroot . '/mod/resource/locallib.php';
     $params = self::validate_parameters(self::add_file_parameters(), array('section' => $section, 'name' => $name, 'path' => $path, 'display' => $display));
     $section = $DB->get_record('course_sections', array('id' => $section), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
     self::require_access($course->id);
     // finally create the file item
     // first add course_module record because we need the context
     $newcm = new stdClass();
     $newcm->course = $course->id;
     $newcm->module = $DB->get_field('modules', 'id', array('name' => 'resource'));
     // not known yet, will be updated later (this is similar to restore code)
     $newcm->instance = 0;
     $newcm->section = $params['section'];
     $newcm->visible = 1;
     $newcm->groupmode = 0;
     $newcm->groupingid = 0;
     $newcm->groupmembersonly = 0;
     if (!($coursemodule = add_course_module($newcm))) {
         throw new invalid_parameter_exception('Error creating course module');
     }
     $config = get_config('resource');
     $module = new stdClass();
     $module->course = $course->id;
     $module->name = format_string($params['name']);
     $module->intro = '<p></p>';
     $module->introformat = 1;
     $module->coursemodule = $coursemodule;
     if (!$display) {
         $module->display = $config->display;
     } else {
         $module->display = $display;
     }
     $module->popupwidth = $config->popupwidth;
     $module->popupheight = $config->popupheight;
     $module->printheading = $config->printheading;
     $module->printintro = $config->printintro;
     // 'Show size' support only from Moodle 2.3 / OU moodle April 2012
     if (isset($config->showsize)) {
         $module->showsize = $config->showsize;
         $module->showtype = $config->showtype;
     }
     $module->filterfiles = $config->filterfiles;
     $module->section = $section->section;
     //check $params['path'] and create files based on that and attach to $module->files
     //now check $path and obtain $filename and $filepath
     $contextuser = get_context_instance(CONTEXT_USER, $USER->id);
     $fs = get_file_storage();
     $module->files = 0;
     file_prepare_draft_area($module->files, null, null, null, null);
     $fileinfo = array('contextid' => $contextuser->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $module->files, 'filepath' => '/', 'filename' => basename($params['path']), 'timecreated' => time(), 'timemodified' => time(), 'mimetype' => mimeinfo('type', $path), 'userid' => $USER->id);
     if (strpos($params['path'], '://') === false) {
         //this is a path
         if (!file_exists($params['path'])) {
             throw new invalid_parameter_exception('Error accessing filepath - file may not exist.');
         }
         $fs->create_file_from_pathname($fileinfo, $params['path']);
     } else {
         //this is a URL - download the file first.
         $content = download_file_content($params['path']);
         if ($content === false) {
             throw new invalid_parameter_exception('Error accessing file - url may not exist.');
         }
         $fs->create_file_from_string($fileinfo, $content);
     }
     $module->instance = resource_add_instance($module, array());
     $DB->set_field('course_modules', 'instance', $module->instance, array('id' => $coursemodule));
     add_mod_to_section($module);
     rebuild_course_cache($course->id, true);
     return array('id' => $coursemodule);
 }
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:77,代码来源:externallib.php

示例14: mime_type

 /** The string mime-type of the files that this plugin reads or writes. */
 public function mime_type() {
     return mimeinfo('type', $this->export_file_extension());
 }
开发者ID:nigeldaley,项目名称:moodle,代码行数:4,代码来源:format.php

示例15: file_folder_view

function file_folder_view($folder)
{
    global $CFG;
    /*
     *    View a specific folder
     *    (Access rights are presumed)
     */
    // Find out who's the owner
    global $page_owner;
    $owner_username = user_info('username', $page_owner);
    // If we're not in the parent folder, provide a link to return to the parent
    /*
    if ($folder->ident != -1) {
        $folder->name = stripslashes($folder->name);
    }
    */
    $body = "<h2>" . $folder->name . "</h2>";
    // Firstly, get a list of folders
    // Display folders we actually have access to
    if ($folder->idents = get_records_select('file_folders', "parent = {$folder->ident} AND (" . run("users:access_level_sql_where") . ") and files_owner = {$page_owner}")) {
        $subFolders = __gettext("Subfolders");
        // gettext variable
        $body .= <<<END

                            <h3>
                                {$subFolders}
                            </h3>

END;
        foreach ($folder->idents as $folder->ident_details) {
            if (run("users:access_level_check", $folder->ident_details->access) == true) {
                $username = $owner_username;
                $ident = (int) $folder->ident_details->ident;
                $name = get_access_description($folder->ident_details->access);
                $name .= stripslashes($folder->ident_details->name);
                $folder->identmenu = file_folder_edit_links($folder->ident_details);
                $keywords = display_output_field(array("", "keywords", "folder", "folder", $ident, $folder->ident_details->owner));
                if ($keywords) {
                    $keywords = __gettext("Keywords: ") . $keywords;
                }
                $body .= templates_draw(array('context' => 'folder', 'username' => $username, 'url' => $CFG->wwwroot . "{$username}/files/{$ident}", 'ident' => $ident, 'name' => $name, 'menu' => $folder->identmenu, 'icon' => $CFG->wwwroot . "mod/file/folder.png", 'keywords' => $keywords));
            }
        }
    }
    // Then get a list of files
    // View files we actually have access to
    if ($files = get_records_select('files', "folder = ? AND files_owner = ?", array($folder->ident, $page_owner))) {
        foreach ($files as $file) {
            if (run("users:access_level_check", $file->access) == true || $file->owner == $_SESSION['userid']) {
                $username = $owner_username;
                $ident = (int) $file->ident;
                $folder->ident = $file->folder;
                $title = get_access_description($file->access);
                $title .= stripslashes($file->title);
                $description = nl2br(stripslashes($file->description));
                $filetitle = urlencode($title);
                $originalname = stripslashes($file->originalname);
                $filemenu = round($file->size / 1048576, 4) . "MB ";
                $icon = $CFG->wwwroot . "_icon/file/" . $file->ident;
                $filepath = $CFG->wwwroot . "{$username}/files/{$folder->ident}/{$ident}/" . urlencode($originalname);
                $mimetype = mimeinfo('type', $file->originalname);
                if ($mimetype == "audio/mpeg" || $mimetype == "audio/mp3") {
                    $filemenu .= " <object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n        codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"\n        width=\"17\" height=\"17\" >\n            <param name=\"allowScriptAccess\" value=\"sameDomain\" />\n            <param name=\"movie\" value=\"" . $CFG->wwwroot . "mod/file/mp3player/musicplayer.swf?song_url={$filepath}&amp;song_title={$filetitle}\" />\n            <param name=\"quality\" value=\"high\" />\n            <embed src=\"" . $CFG->wwwroot . "mod/file/mp3player/musicplayer.swf?song_url={$filepath}&amp;song_title={$filetitle}\"\n            quality=\"high\" bgcolor=\"#E6E6E6\" name=\"xspf_player\" allowscriptaccess=\"sameDomain\"\n            type=\"application/x-shockwave-flash\"\n            pluginspage=\"http://www.macromedia.com/go/getflashplayer\"\n            align=\"center\" height=\"17\" width=\"17\" />\n        </object>";
                }
                $filemenu = file_edit_links($file);
                $keywords = display_output_field(array("", "keywords", "file", "file", $ident, $file->owner));
                if ($keywords) {
                    $keywords = __gettext("Keywords: ") . $keywords;
                }
                $body .= templates_draw(array('context' => 'file', 'username' => $username, 'title' => $title, 'ident' => $ident, 'folder' => $folder->ident, 'description' => $description, 'originalname' => $originalname, 'url' => $filepath, 'menu' => $filemenu, 'icon' => $icon, 'keywords' => $keywords));
                $body .= display_run_displayobjectannotations($file, "file::file");
            }
        }
    }
    // Deliver an apologetic message if there aren't any files or folders
    if (empty($files) && empty($folder->idents)) {
        $body .= "<p>" . __gettext("This folder is currently empty.") . "</p>";
    }
    return $body;
}
开发者ID:BackupTheBerlios,项目名称:tulipan-svn,代码行数:80,代码来源:lib.php


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