[system] / trunk / wwmoodle / wwquestion / file.php Repository:
ViewVC logotype

View of /trunk/wwmoodle/wwquestion/file.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5477 - (download) (as text) (annotate)
Sun Sep 9 02:53:16 2007 UTC (12 years, 5 months ago) by mleventi
File size: 2686 byte(s)
*** empty log message ***

    1 <?php
    2     //This script fetches files from wwquestions directory, and only that directory.
    3     //It is used to display the cached equation images that are copied to moodledata when derived questions are created
    4 
    5     require_once('../../../config.php');
    6     require_once($CFG->libdir . '/filelib.php');
    7 
    8     // disable moodle specific debug messages
    9     disable_debugging();
   10 
   11     $relativepath = get_file_argument('file.php');
   12     $forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
   13 
   14     // relative path must start with '/', because of backup/restore!!!
   15     if (!$relativepath) {
   16         error('No valid arguments supplied or incorrect server configuration');
   17     } else if ($relativepath{0} != '/') {
   18         error('No valid arguments supplied, path does not start with slash!');
   19     }
   20 
   21     $pathname = $CFG->dataroot.$relativepath;
   22 
   23     // extract relative path components
   24     $args = explode('/', trim($relativepath, '/'));
   25 
   26     //security this should only be used for wwquestions
   27     if ((count($args) < 3) || ($args[0] != '1') || ($args[1] != 'wwquestions')) {
   28         error('No valid arguments supplied');
   29     }
   30 
   31     //extra security for users
   32     if($args[1] == 'users') {
   33         //trying to get a user equation image
   34         //BEEF this up with roles etc, so teachers have access to students pics so on.
   35         if($args[2] != $USER->id) {
   36             error('Access Denied to this Equation Image');
   37         }
   38     }
   39 
   40 
   41 
   42     if (is_dir($pathname)) {
   43         if (file_exists($pathname.'/index.html')) {
   44             $pathname = rtrim($pathname, '/').'/index.html';
   45             $args[] = 'index.html';
   46         } else if (file_exists($pathname.'/index.htm')) {
   47             $pathname = rtrim($pathname, '/').'/index.htm';
   48             $args[] = 'index.htm';
   49         } else if (file_exists($pathname.'/Default.htm')) {
   50             $pathname = rtrim($pathname, '/').'/Default.htm';
   51             $args[] = 'Default.htm';
   52         } else {
   53             // security: do not return directory node!
   54             not_found($course->id);
   55         }
   56     }
   57 
   58     // check that file exists
   59     if (!file_exists($pathname)) {
   60         not_found($course->id);
   61     }
   62 
   63     // ========================================
   64     // finally send the file
   65     // ========================================
   66     session_write_close(); // unlock session during fileserving
   67     $filename = $args[count($args)-1];
   68     send_file($pathname, $filename);
   69 
   70     function not_found($courseid) {
   71         global $CFG;
   72         header('HTTP/1.0 404 not found');
   73         error(get_string('filenotfound', 'error'), $CFG->wwwroot.'/course/view.php?id='.$courseid); //this is not displayed on IIS??
   74     }
   75 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9