Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to download files from links?
  2. <?php
  3.  
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_URL,"http://example.com");
  6. curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  8. $result=curl_exec ($ch);
  9. curl_close ($ch);
  10.  
  11. // search the results from the starting site
  12. if( $result ){
  13.    preg_match_all('/<a href="(http://www.[^0-9]+.pdf?)"/', $result, $output, PREG_SET_ORDER );
  14.      foreach($output as $item  ){
  15.         print_r($item );
  16.       }
  17. }
  18. copy($item, 'file.pdf');
  19. ?>
  20.        
  21. // Set your save path here
  22. $path = '/home/igos/pdfs/';
  23.  
  24. foreach($output as $item){
  25.     copy($item, $path . basename($item));
  26.   }
  27.        
  28. <?php
  29. set_time_limit(0);
  30. include 'simple_html_dom.php';
  31. $url='example.com';
  32. //set your save path here
  33. $path = '/home/igos/pdfs/';
  34.  
  35. $html = file_get_html($url) or die ('invalid url');
  36. foreach($html->find('a') as $e) {
  37.      $link= $e->href;
  38.      if (preg_match('/.pdf$/i', $link)) {
  39.           $result[] = $link;
  40.           copy($link, $path . basename($link));
  41.      }
  42. }
  43.  
  44. ?>