]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16007 - add new $dontdie parameter to the send_ file functions
authormjollnir_ <mjollnir_>
Tue, 12 Aug 2008 12:54:54 +0000 (12:54 +0000)
committermjollnir_ <mjollnir_>
Tue, 12 Aug 2008 12:54:54 +0000 (12:54 +0000)
lib/filelib.php

index c90b7fc344b82ef4598c84eff03f709a498bcdf3..b6b5921490a0eb50ec1d9df518fbfe4235667fb4 100644 (file)
@@ -567,10 +567,17 @@ function get_mimetype_description($mimetype,$capitalise=false) {
  * @param string $path path to file, preferably from moodledata/temp/something; or content of file itself
  * @param string $filename proposed file name when saving file
  * @param bool $path is content of file
+ * @param bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
+ *                        if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
+ *                        you must detect this case when control is returned using connection_aborted.
  */
-function send_temp_file($path, $filename, $pathisstring=false) {
+function send_temp_file($path, $filename, $pathisstring=false, $dontdie=false) {
     global $CFG;
 
+    if ($dontdie) {
+        ignore_user_abort();
+    }
+
     // close session - not needed anymore
     @session_write_close();
 
@@ -615,6 +622,9 @@ function send_temp_file($path, $filename, $pathisstring=false) {
         readfile_chunked($path);
     }
 
+    if ($dontdie) {
+        return;
+    }
     die; //no more chars to output
 }
 
@@ -637,10 +647,17 @@ function send_temp_file_finished($path) {
  * @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
+ * @param bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
+ *                        if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
+ *                        you must detect this case when control is returned using connection_aborted.
  */
-function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='') {
+function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false) {
     global $CFG, $COURSE, $SESSION;
 
+    if ($dontdie) {
+        ignore_user_abort();
+    }
+
     // MDL-11789, apply $CFG->filelifetime here
     if ($lifetime === 'default') {
         if (!empty($CFG->filelifetime)) {
@@ -826,6 +843,9 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
             }
         }
     }
+    if ($dontdie) {
+        return;
+    }
     die; //no more chars to output!!!
 }
 
@@ -838,10 +858,17 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
  * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
  * @param string $filename Override filename
  * @param string $mimetype Include to specify the MIME type; leave blank to have it guess the type from $filename
+ * @param bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
+ *                        if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
+ *                        you must detect this case when control is returned using connection_aborted.
  */
-function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, $filename=null) {
+function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, $filename=null, $dontdie=false) {
     global $CFG, $COURSE, $SESSION;
 
+    if ($dontdie) {
+        ignore_user_abort();
+    }
+
     session_write_close(); // unlock session during fileserving
 
     // Use given MIME type if specified, otherwise guess it using mimeinfo.
@@ -997,6 +1024,9 @@ function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownl
             $stored_file->readfile();
         }
     }
+    if ($dontdie) {
+        return;
+    }
     die; //no more chars to output!!!
 }