From 9b307a83ee61a4896227f453603a5991ad5a1f5f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 31 Aug 2005 22:55:50 +0200 Subject: 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 --- inc/io.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'inc/io.php') 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 - * @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 -- cgit v1.2.3