summaryrefslogtreecommitdiff
path: root/inc/io.php
diff options
context:
space:
mode:
authorchris <chris@teacherscpd.co.uk>2005-09-11 16:21:26 +0200
committerchris <chris@teacherscpd.co.uk>2005-09-11 16:21:26 +0200
commit73ccfcb964771f4bd540838c32791a1d49e29d5f (patch)
tree1b629e5139acde7c5c82e7626e62f58d2844dc0f /inc/io.php
parent683757541c99dba48c30662ba2b60db34352165f (diff)
downloadrpg-73ccfcb964771f4bd540838c32791a1d49e29d5f.tar.gz
rpg-73ccfcb964771f4bd540838c32791a1d49e29d5f.tar.bz2
io_download mod to allow use of attachment names, plugin manager fix to use new io_download
darcs-hash:20050911142126-50fdc-dd1b45c40b33153c3ea993ec53c11d063c34154c.gz
Diffstat (limited to 'inc/io.php')
-rw-r--r--inc/io.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/inc/io.php b/inc/io.php
index c25bd8975..1939dc6a0 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -259,22 +259,52 @@ function io_mkdir_ftp($dir){
}
/**
- * downloads a file from the net and saves it to the given location
+ * downloads a file from the net and saves it
+ *
+ * if $useAttachment is false,
+ * - $file is the full filename to save the file, incl. path
+ * - if successful will return true, false otherwise
+
+ * if $useAttachment is true,
+ * - $file is the directory where the file should be saved
+ * - if successful will return the name used for the saved file, false otherwise
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Chris Smith <chris@jalakai.co.uk>
*/
-function io_download($url,$file){
+function io_download($url,$file,$useAttachment=false,$defaultName=''){
$http = new DokuHTTPClient();
$http->max_bodysize = 2*1024*1024; //max. 2MB
$http->timeout = 25; //max. 25 sec
$data = $http->get($url);
if(!$data) return false;
+
+ if ($useAttachment) {
+ $name = '';
+ if (isset($http->resp_headers['content-disposition'])) {
+ $content_disposition = $http->resp_headers['content-disposition'];
+ if (is_string($content_disposition) &&
+ preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match=array())) {
+
+ $name = basename($match[1]);
+ }
+
+ }
+
+ if (!$name) {
+ if (!$defaultName) return false;
+ $name = $defaultName;
+ }
+
+ $file = $file.$name;
+ }
$fp = @fopen($file,"w");
if(!$fp) return false;
fwrite($fp,$data);
fclose($fp);
+ if ($useAttachment) return $name;
return true;
}