summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2015-01-26 20:28:49 +0100
committerSimon Rettberg2015-01-26 20:28:49 +0100
commit5347ecd5ddb1803ec1c43240bafc84f5c427f855 (patch)
tree7a852cdaa44599dab5f4c98b9daa7c6443d81024 /inc/util.inc.php
parentFix stupid bug in update query, check DB version before handling callbacks (diff)
downloadslx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.tar.gz
slx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.tar.xz
slx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.zip
Add configtgz class. Fix dozens of bugs
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 9d0eced9..d2ecba6f 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -232,5 +232,45 @@ SADFACE;
}
return true;
}
+
+ /**
+ * Send a file to user for download.
+ *
+ * @param type $file path of local file
+ * @param type $name name of file to send to user agent
+ * @param type $delete delete the file when done?
+ * @return boolean false: file could not be opened.
+ * true: error while reading the file
+ * - on success, the function does not return
+ */
+ public static function sendFile($file, $name, $delete = false)
+ {
+ while ((@ob_get_level()) > 0)
+ @ob_end_clean();
+ $fh = @fopen($file, 'rb');
+ if ($fh === false) {
+ Message::addError('error-read', $file);
+ return false;
+ }
+ Header('Content-Type: application/octet-stream', true);
+ Header('Content-Disposition: attachment; filename=' . str_replace(array(' ', '=', ',', '/', '\\', ':', '?'), '_', iconv('UTF-8', 'ASCII//TRANSLIT', $name)));
+ Header('Content-Length: ' . @filesize($file));
+ while (!feof($fh)) {
+ $data = fread($fh, 16000);
+ if ($data === false) {
+ echo "\r\n\nDOWNLOAD INTERRUPTED!\n";
+ if ($delete)
+ @unlink($file);
+ return true;
+ }
+ echo $data;
+ @ob_flush();
+ @flush();
+ }
+ @fclose($fh);
+ if ($delete)
+ @unlink($file);
+ exit(0);
+ }
}