Hi
ive got a project im working on where i need to collect a whole bunch of images from a website (photo.net) and decided a PHP script might help automate the process. A few other people may work on the project in the future so im leaving detailed comments on most lines to help them understand the code so far im stuck with a few aspects of the coding process: 1. I have a URL, but need to know how to open a random page on that URL, specifically a page with a picture on it, such as http://photo.net/photodb/photo?photo_id=18012098, i have thought about using "http://photo.net/photodb/photo?photo_id=" as the URL and randomly generating an 8 digit number at the end, but manually tested it out and there are alot of combinations that result in an error page (such as http://photo.net/photodb/photo?photo_id=10012098), so would need a method more reliable.
2. As far as the file name ill be using goes theres certain criteria, ill need the name of the photo, the rating and the number of votes (all of which are located in the details tab of each photo), these details are combined to create a file name, in the example of the following photo http://photo.net/photodb/photo?photo_id=18012098, the filename id need the generate would be something like "Chameleon Snatches Hornworm 6.23 13.jpg" Im having trouble figuring out how to get my php script to scan a page for info and store it in a variable
3. and finally i need to know how to actually rip the image from the page, saving it under the $foldername and #filename variables
the code ive written so far is below, any help i can get on any of these 3 issues would be very much appreciated
thank you,
function download_image
{
//File Path variable, change to path you wish to download files to (be sure to end with a slash "\")
$folderpath = "E:\Pictures\";
//Website Variable, Change to the website youre downloading photos from
$url = "http://photo.net/";
//Number of Photos, change variable to indicate the number of photos you wish to download at any one time
$photos=10;
//Main Loop, this will find photos in the URL, assign a file name and save the photo to the specified file path
for ($i = 0; $i <= $photos; $i++) {
//Opens picture random picture from URL
// Assigns filename
// Gets the name of the picture (adjust if using a website other than photo.net)
$picturename = ;
// Gets the rating of the picture (adjust if using a website other than photo.net)
$rating = ;
// Gets the number of votes for the picture (adjust if using a website other than photo.net)
$votes= ;
//combines all these variables to create the filename
$filename= $picturename . " " . $rating . " " . $votes . ".jpg";
//checks rating, if "critique only" then move on to another photo
if ($rating = "Critique Only") {
//if no proper rating deduct 1 from $i
i--;
} else {
//Checks Folder to see if file already exists (if so, it deducts one from $i variable, this will ensure that the right number of photos are downloaded without downloading doubles)
$filepath = $folderpath . $filename;
if (file_exists($filepath)) {
//if file exists deduct 1 from $i
$i--;
} else {
//if file doesnt exist download picture to folder
}
}
}
}