Index: lib/filelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/filelib.php,v retrieving revision 1.39.2.10 diff -u -F ^f -r1.39.2.10 filelib.php --- lib/filelib.php 30 Oct 2007 00:32:27 -0000 1.39.2.10 +++ lib/filelib.php 7 Apr 2008 04:07:09 -0000 @@ -4,6 +4,40 @@ define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7'); //unique string constant +function get_file_url($path, $options=null, $type='coursefile') { + global $CFG; + + $path = trim($path, '/'); // no leading and trailing slashes + + // type of file + switch ($type) { + case 'coursefile': + default: + $url = "$CFG->wwwroot/file.php"; + } + + if ($CFG->slasharguments) { + $parts = explode('/', $path); + $parts = array_map('urlencode', $parts); + $path = implode('/', $parts); + $ffurl = "$CFG->wwwroot/file.php/$path"; + $separator = '?'; + } else { + $path = urlencode("/$path"); + $ffurl = "$CFG->wwwroot/file.php?file=$path"; + $separator = '&'; + } + + if ($options) { + foreach ($options as $name=>$value) { + $ffurl = $ffurl.$separator.$name.'='.$value; + $separator = '&'; + } + } + + return $ffurl; +} + /** * Fetches content of file from Internet (using proxy if defined). * Index: mod/assignment/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/assignment/lib.php,v retrieving revision 1.219.2.24 diff -u -F ^f -r1.219.2.24 lib.php --- mod/assignment/lib.php 14 Feb 2008 07:17:52 -0000 1.219.2.24 +++ mod/assignment/lib.php 7 Apr 2008 04:07:10 -0000 @@ -1494,12 +1494,8 @@ $icon = mimeinfo('icon', $file); - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } - + $ffurl = get_file_url("$filearea/$file", array('forcedownload'=>1)); + $output .= ''.$icon.''. ''.$file.'
'; } Index: mod/assignment/type/upload/assignment.class.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/assignment/type/upload/assignment.class.php,v retrieving revision 1.29.2.7 diff -u -F ^f -r1.29.2.7 assignment.class.php --- mod/assignment/type/upload/assignment.class.php 1 Apr 2008 20:24:00 -0000 1.29.2.7 +++ mod/assignment/type/upload/assignment.class.php 7 Apr 2008 04:07:10 -0000 @@ -265,10 +265,10 @@ } if ($files = get_directory_list($basedir, 'responses')) { + require_once($CFG->libdir.'/filelib.php'); foreach ($files as $key => $file) { - require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $file); - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.' '; } } @@ -326,9 +326,7 @@ foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); - - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.''; @@ -381,8 +379,7 @@ foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); - - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.''; Index: mod/assignment/type/uploadsingle/assignment.class.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/assignment/type/uploadsingle/assignment.class.php,v retrieving revision 1.30.2.5 diff -u -F ^f -r1.30.2.5 assignment.class.php --- mod/assignment/type/uploadsingle/assignment.class.php 1 Apr 2008 20:24:00 -0000 1.30.2.5 +++ mod/assignment/type/uploadsingle/assignment.class.php 7 Apr 2008 04:07:10 -0000 @@ -16,17 +16,12 @@ if ($basedir = $this->file_area($userid)) { if ($files = get_directory_list($basedir)) { - + require_once($CFG->libdir.'/filelib.php'); foreach ($files as $key => $file) { - require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $file); - - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } + $ffurl = get_file_url("$filearea/$file"); + //died right here //require_once($ffurl); $output = ''.$icon.''.