mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-13 11:56:29 +00:00
Add download file with callback examples
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->download('https://php.net/images/logos/php-med-trans.png', function($instance, $tmpfile) {
|
||||
$save_to_path = '/tmp/_' . basename($instance->url);
|
||||
$fh = fopen($save_to_path, 'wb');
|
||||
stream_copy_to_stream($tmpfile, $fh);
|
||||
fclose($fh);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$callback = function($instance, $tmpfile) {
|
||||
$save_to_path = '/tmp/' . basename($instance->url);
|
||||
$fh = fopen($save_to_path, 'wb');
|
||||
stream_copy_to_stream($tmpfile, $fh);
|
||||
fclose($fh);
|
||||
};
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
$multi_curl->addDownload('https://php.net/images/logos/php-med-trans.png', $callback);
|
||||
$multi_curl->addDownload('https://upload.wikimedia.org/wikipedia/commons/c/c1/PHP_Logo.png', $callback);
|
||||
$multi_curl->start();
|
||||
Reference in New Issue
Block a user