
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.98 KB | hits: 13 | expires: Never
how to download files from links?
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com");
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
// search the results from the starting site
if( $result ){
preg_match_all('/<a href="(http://www.[^0-9]+.pdf?)"/', $result, $output, PREG_SET_ORDER );
foreach($output as $item ){
print_r($item );
}
}
copy($item, 'file.pdf');
?>
// Set your save path here
$path = '/home/igos/pdfs/';
foreach($output as $item){
copy($item, $path . basename($item));
}
<?php
set_time_limit(0);
include 'simple_html_dom.php';
$url='example.com';
//set your save path here
$path = '/home/igos/pdfs/';
$html = file_get_html($url) or die ('invalid url');
foreach($html->find('a') as $e) {
$link= $e->href;
if (preg_match('/.pdf$/i', $link)) {
$result[] = $link;
copy($link, $path . basename($link));
}
}
?>