]> git.mjollnir.org Git - moodle.git/commitdiff
Minor changes to send_file():
authorsam_marshall <sam_marshall>
Wed, 5 Jul 2006 11:10:37 +0000 (11:10 +0000)
committersam_marshall <sam_marshall>
Wed, 5 Jul 2006 11:10:37 +0000 (11:10 +0000)
* Wrote phpdoc comment that documents all parameters
* Added $mimetype param (default empty) that can be used if MIME type is already known and doesn't need guessing from filename

lib/filelib.php

index cd47fb1ea3c571ede204c2cf00858653028083da..963dd53440a2e3b3e248ef61c669ecb2e735275e 100644 (file)
@@ -203,12 +203,23 @@ function get_mimetype_description($mimetype,$capitalise=false) {
 }
 
 /** 
- * @PARAM $filter int 0=no filtering, 1=all files, 2=html files only
+ * Handles the sending of file data to the user's browser, including support for 
+ * byteranges etc. 
+ * @param string $path Path of file on disk (including real filename), or actual content of file as string
+ * @param string $filename Filename to send
+ * @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 $pathisstring If true (default false), $path is the content to send and not the pathname
+ * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
+ * @param string $mimetype Include to specify the MIME type; leave blank to have it guess the type from $filename
  */
-function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=false, $forcedownload=false) {
+function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='') {
     global $CFG;
 
-    $mimetype     = $forcedownload ? 'application/x-forcedownload' : mimeinfo('type', $filename);
+    // Use given MIME type if specified, otherwise guess it using mimeinfo. 
+    // Always use application/x-forcedownload if that's requested.
+    $mimetype     = $forcedownload ? 'application/x-forcedownload' : 
+                        ($mimetype ? $mimetype : mimeinfo('type', $filename));
     $lastmodified = $pathisstring ? time() : filemtime($path);
     $filesize     = $pathisstring ? strlen($path) : filesize($path);