require_once 'snoopy.php';
$snoopy = new snoopy();
$snoopy->fetch('http://site.com/image.png');
$image = $snoopy->results;
$fh = fopen('image.png', 'w');
fwrite($fh, $image);
fclose($fh);
file_put_contents('image.png', file_get_contents('http://site.com/image.png'));
$fh = fopen('image.png', 'w');
fwrite($fh, file_get_contents('http://site.com/image.png'));
fclose($fh);
<?php
if (isset($_GET['url']) && eregi("^(http://)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?((([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2})|(([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.(com|net|org|edu|mil|gov|int|aero|coop|museum|name|info|biz|pro|[a-z]{2})))(:[1-6]?[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+(\.jpg|\.gif|\.png|\.jpeg)$", $_GET['url'])) {
$image = file_get_contents($_GET['url']);
if (!$image) {
die("Unable to fetch URL");
}
$f = fopen("imagefile", "w");
if (!$f) {
die("Unable to open file for writing");
}
fwrite($f, $image);
fclose($f);
} else {
die("Invalid Image URL");
}
?>
Beansprout said:Why not just preg_match() (or ereg-whatever) the characters after the last full stop (ie the extension), rather than try and regex the whole URL....that one currently cuts out a whole bunch of the intarweb (.co.uk, .whatever.uk, and lottttttts of others)![]()
...(com|net|org|edu|mil|gov|int|aero|coop|museum|name|info|biz|pro|[b][a-z]{2}[/b])...
preg_match("/\.(jp(e?)g|gif|png|(w?)bmp)$/i",$url);