mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-27125_master_2' of git://git.catalyst.net.nz/moodle-r2
This commit is contained in:
commit
c425663c4c
3 changed files with 43 additions and 8 deletions
|
@ -3006,14 +3006,36 @@ class curl {
|
||||||
* Calls {@link multi()} with specific download headers
|
* Calls {@link multi()} with specific download headers
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* $c = new curl;
|
* $c = new curl();
|
||||||
|
* $file1 = fopen('a', 'wb');
|
||||||
|
* $file2 = fopen('b', 'wb');
|
||||||
* $c->download(array(
|
* $c->download(array(
|
||||||
* array('url'=>'http://localhost/', 'file'=>fopen('a', 'wb')),
|
* array('url'=>'http://localhost/', 'file'=>$file1),
|
||||||
* array('url'=>'http://localhost/20/', 'file'=>fopen('b', 'wb'))
|
* array('url'=>'http://localhost/20/', 'file'=>$file2)
|
||||||
|
* ));
|
||||||
|
* fclose($file1);
|
||||||
|
* fclose($file2);
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* or
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* $c = new curl();
|
||||||
|
* $c->download(array(
|
||||||
|
* array('url'=>'http://localhost/', 'filepath'=>'/tmp/file1.tmp'),
|
||||||
|
* array('url'=>'http://localhost/20/', 'filepath'=>'/tmp/file2.tmp')
|
||||||
* ));
|
* ));
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $requests An array of files to request
|
* @param array $requests An array of files to request {
|
||||||
|
* url => url to download the file [required]
|
||||||
|
* file => file handler, or
|
||||||
|
* filepath => file path
|
||||||
|
* }
|
||||||
|
* If 'file' and 'filepath' parameters are both specified in one request, the
|
||||||
|
* open file handle in the 'file' parameter will take precedence and 'filepath'
|
||||||
|
* will be ignored.
|
||||||
|
*
|
||||||
* @param array $options An array of options to set
|
* @param array $options An array of options to set
|
||||||
* @return array An array of results
|
* @return array An array of results
|
||||||
*/
|
*/
|
||||||
|
@ -3037,11 +3059,15 @@ class curl {
|
||||||
$results = array();
|
$results = array();
|
||||||
$main = curl_multi_init();
|
$main = curl_multi_init();
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$url = $requests[$i];
|
if (!empty($requests[$i]['filepath']) and empty($requests[$i]['file'])) {
|
||||||
foreach($url as $n=>$v){
|
// open file
|
||||||
$options[$n] = $url[$n];
|
$requests[$i]['file'] = fopen($requests[$i]['filepath'], 'w');
|
||||||
|
$requests[$i]['auto-handle'] = true;
|
||||||
}
|
}
|
||||||
$handles[$i] = curl_init($url['url']);
|
foreach($requests[$i] as $n=>$v){
|
||||||
|
$options[$n] = $v;
|
||||||
|
}
|
||||||
|
$handles[$i] = curl_init($requests[$i]['url']);
|
||||||
$this->apply_opt($handles[$i], $options);
|
$this->apply_opt($handles[$i], $options);
|
||||||
curl_multi_add_handle($main, $handles[$i]);
|
curl_multi_add_handle($main, $handles[$i]);
|
||||||
}
|
}
|
||||||
|
@ -3058,6 +3084,13 @@ class curl {
|
||||||
curl_multi_remove_handle($main, $handles[$i]);
|
curl_multi_remove_handle($main, $handles[$i]);
|
||||||
}
|
}
|
||||||
curl_multi_close($main);
|
curl_multi_close($main);
|
||||||
|
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
if (!empty($requests[$i]['filepath']) and !empty($requests[$i]['auto-handle'])) {
|
||||||
|
// close file handler if file is opened in this function
|
||||||
|
fclose($requests[$i]['file']);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,6 +206,7 @@ class repository_alfresco extends repository {
|
||||||
$fp = fopen($path, 'w');
|
$fp = fopen($path, 'w');
|
||||||
$c = new curl;
|
$c = new curl;
|
||||||
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||||
|
fclose($fp);
|
||||||
return array('path'=>$path, 'url'=>$url);
|
return array('path'=>$path, 'url'=>$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,7 @@ class repository_flickr extends repository {
|
||||||
$c->download(array(
|
$c->download(array(
|
||||||
array('url'=>$url, 'file'=>$fp)
|
array('url'=>$url, 'file'=>$fp)
|
||||||
));
|
));
|
||||||
|
fclose($fp);
|
||||||
return array('path'=>$path, 'url'=>$url);
|
return array('path'=>$path, 'url'=>$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue