download.php 658 B

12345678910111213141516171819202122232425
  1. <?php
  2. require '_inc.php';
  3. use Ares333\Curl\Toolkit;
  4. $toolkit = new Toolkit();
  5. $toolkit->setCurl();
  6. $curl = $toolkit->getCurl();
  7. $curl->onInfo = null;
  8. $url = 'http://www.baidu.com/img/bd_logo1.png';
  9. $file = __DIR__ . '/output/download.png';
  10. // $fp is closed automatically on download finished.
  11. $fp = fopen($file, 'w');
  12. $curl->add(
  13. array(
  14. 'opt' => array(
  15. CURLOPT_URL => $url,
  16. CURLOPT_FILE => $fp,
  17. CURLOPT_HEADER => false
  18. ),
  19. 'args' => array(
  20. 'file' => $file
  21. )
  22. ),
  23. function ($r, $args) {
  24. echo "download finished successfully, file=$args[file]\n";
  25. })->start();