summaryrefslogtreecommitdiff
path: root/inc/io.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-08-31 22:55:50 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-08-31 22:55:50 +0200
commit9b307a83ee61a4896227f453603a5991ad5a1f5f (patch)
treeffa2d77cbcdb79f639a912bb91fc0bb53830579e /inc/io.php
parentdbb00abcfb0db727767b60293e390e4adc959398 (diff)
downloadrpg-9b307a83ee61a4896227f453603a5991ad5a1f5f.tar.gz
rpg-9b307a83ee61a4896227f453603a5991ad5a1f5f.tar.bz2
HTTP Client added
This patch adds an HTTP client written in PHP. It supports proxy handling and SSL if PHP was compiled with it. darcs-hash:20050831205550-7ad00-6dcdff0208d7f18a8ff731febb155d126742c768.gz
Diffstat (limited to 'inc/io.php')
-rw-r--r--inc/io.php28
1 files changed, 10 insertions, 18 deletions
diff --git a/inc/io.php b/inc/io.php
index 5cf50af8f..c25bd8975 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -8,6 +8,7 @@
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/common.php');
+ require_once(DOKU_INC.'inc/HTTPClient.php');
/**
* Removes empty directories
@@ -261,30 +262,21 @@ function io_mkdir_ftp($dir){
* downloads a file from the net and saves it to the given location
*
* @author Andreas Gohr <andi@splitbrain.org>
- * @todo Add size limit
*/
function io_download($url,$file){
- $fp = @fopen($url,"rb");
- if(!$fp) return false;
+ $http = new DokuHTTPClient();
+ $http->max_bodysize = 2*1024*1024; //max. 2MB
+ $http->timeout = 25; //max. 25 sec
- $kb = 0;
- $now = time();
+ $data = $http->get($url);
+ if(!$data) return false;
- while(!feof($fp)){
- if($kb++ > 2048 || (time() - $now) > 45){
- //abort on 2 MB and timeout on 45 sec
- return false;
- }
- $cont.= fread($fp,1024);
- }
+ $fp = @fopen($file,"w");
+ if(!$fp) return false;
+ fwrite($fp,$data);
fclose($fp);
-
- $fp2 = @fopen($file,"w");
- if(!$fp2) return false;
- fwrite($fp2,$cont);
- fclose($fp2);
return true;
-}
+}
/**
* Runs an external command and returns it's output as string