Skip to content

Commit 6c2b848

Browse files
committed
Add download file with callback examples
1 parent c03749b commit 6c2b848

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
require '../src/Curl/Curl.php';
3+
4+
use \Curl\Curl;
5+
6+
$curl = new Curl();
7+
$curl->download('https://php.net/images/logos/php-med-trans.png', function($instance, $tmpfile) {
8+
$save_to_path = '/tmp/_' . basename($instance->url);
9+
$fh = fopen($save_to_path, 'wb');
10+
stream_copy_to_stream($tmpfile, $fh);
11+
fclose($fh);
12+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
require '../src/Curl/Curl.php';
3+
require '../src/Curl/MultiCurl.php';
4+
5+
use \Curl\Curl;
6+
use \Curl\MultiCurl;
7+
8+
$callback = function($instance, $tmpfile) {
9+
$save_to_path = '/tmp/' . basename($instance->url);
10+
$fh = fopen($save_to_path, 'wb');
11+
stream_copy_to_stream($tmpfile, $fh);
12+
fclose($fh);
13+
};
14+
15+
$multi_curl = new MultiCurl();
16+
$multi_curl->addDownload('https://php.net/images/logos/php-med-trans.png', $callback);
17+
$multi_curl->addDownload('https://upload.wikimedia.org/wikipedia/commons/c/c1/PHP_Logo.png', $callback);
18+
$multi_curl->start();

0 commit comments

Comments
 (0)