MDL-15349, the implementation of get_file function in repository class.

This commit is contained in:
dongsheng 2008-07-16 05:15:14 +00:00
parent c5b443d59c
commit c425472d81
2 changed files with 30 additions and 7 deletions

View File

@ -1,4 +1,4 @@
<?php // $id$ <?php // $Id$
/** /**
* RESTful cURL class * RESTful cURL class
* *
@ -266,7 +266,7 @@ class curl {
* )); * ));
*/ */
public function download($requests, $options = array()) { public function download($requests, $options = array()) {
$options['returntransfer'] = false; $options['RETURNTRANSFER'] = false;
return $this->mulit_request($requests, $options); return $this->mulit_request($requests, $options);
} }
/* /*
@ -293,7 +293,11 @@ class curl {
} while($running > 0); } while($running > 0);
for($i = 0; $i < $count; $i++) for($i = 0; $i < $count; $i++)
{ {
$results[] = curl_multi_getcontent($handles[$i]); if(!empty($optins['CURLOPT_RETURNTRANSFER'])) {
$results[] = true;
} else {
$results[] = curl_multi_getcontent($handles[$i]);
}
curl_multi_remove_handle($main, $handles[$i]); curl_multi_remove_handle($main, $handles[$i]);
} }
curl_multi_close($main); curl_multi_close($main);

View File

@ -47,7 +47,7 @@
* $repo->print_search(); * $repo->print_search();
* *
* @version 1.0 dev * @version 1.0 dev
* @package repository_api * @package repository
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/ */
require_once('../config.php'); require_once('../config.php');
@ -99,9 +99,28 @@ abstract class repository {
public function __toString() { public function __toString() {
return 'Repository class: '.__CLASS__; return 'Repository class: '.__CLASS__;
} }
// Given a URL, get a file from there. /**
public function get_file($url) { * Given a URL, get a file from there.
return null; * @param string $url the url of file
* @param string $file save location
*/
public function get_file($url, $file) {
global $CFG;
if(file_exists($CFG->dirroot.'/repository/curl.class.php')) {
if(!file_exists($file)){
return null;
} else {
$file = fopen($file, 'w');
}
require_once($CFG->dirroot.'/repository/curl.class.php');
$c = new curl;
$c->download(array(
array('url'=>$url, 'file'=>$file);
));
return true;
} else {
return null;
}
} }
/** /**