Hi again, I'm trying to download a library of images that are made publicly available on a certain site. The script I made below works fine on other sites, but this site has hotlink protection on. Is there still a way to download the images with php? When i download an image and open it with php, the image says "Hotlink protection enabled." There's roughly 2,500 photo's, all of them are under 35kb user submitted content. For those of you who are morally against this, hotlink protection is(mostly) used to keep people from post your images on their site which results serious bandwidth loss, I will be using up 85mb of bandwidth, which I'm sure I've already done just browsing the site. I just want to make a copy once. Any ideas?
Here's the script I have, maybe some of you will find it useful as is.

<?php

include('con.php');
//$i = 5051;
$i = $_GET['count'];
$url = "http://www.DOMAIN.com/pic";

while($i > 0)
{
	$html = file_get_contents($url.$i.'/');

$html = explode("<img border=0 src='/rm/images/", $html);
$html = explode("' width=", $html[1]);
//html[0] is the image name at this point



$img = $html[0];
//$img is the image file name

$copydir = "/home/<NAME>/public_html/test/";

$data = file_get_contents("http://www.<URL PATH REPLACED>".$img);
$ext = explode(".",$img);


do 
{
	$img = md5($img);
	$img .= ".".$ext[1];
}
while(file_exists("test/$img"));


$file = fopen($copydir . $img, "w+");
fputs($file, $data);
fclose($file);

$md5 = md5_file("test/$img");

mysql_query("INSERT INTO images (`image`,`ip`,`md5`,`approved`) VALUES ('$img','FKscript','$md5','no')");

echo "Image $i done <br/>";
$i--;
sleep(0.5);

}
mysql_close($con);

?> 

PS: I really don't feel like sitting there and dragging 2,500 images to my desktop, although I will if i have to.. lol.

    You'd probably have to use [man]cURL[/man] and send an appropriate HTTP_REFERER header as part of the request.

      Write a Reply...