I have a program here, that is supposed to download a predefined list of images (up to about 1500 at a time - and no, this is not about adult content :-P).
What i would like the script to do, is give the user an update about what it;s doing at any given point. something like:
file_001.jpg ... done
file_002.jpg ... done
file_003.jpg ... done
file_004.jpg ... error
file_005.jpg ... done
file_006.jpg ... done
file_007.jpg ...
you get the idea. the reasoning behind that is, that the page will load forever and a day when it downloads such an amount of data. for 106 files it took 36.7 sec. If that's an average number, 1500 files would take somewhere between 9 and 10 minutes. To prevent the users from getting bored/closing the window, iId like them to see that progress.
I have tried it with [man]flush/man, but the result was no different than laving it out. Here is the procedure of the product class, which will take care of the downloads. it downloads all images that belong to a certain product (up to 32/product - usually around 8) and is invoked for each product in a category (up to 100 products):
<?php
Class ... {
//...
function extract_images() {
$img = array();
$img = $this->generate_image_filenames();
foreach ($img AS $key => $val) {
$url = BASE_URL . $this->id . $val . ".jpg";
$file = DIR_CACHE_IMAGES . md5($this->id . $val . CACHE_SALT) . ".jpg";
is_file($file) ? unlink($file) : false;
if (!copy($url, $file)) {
error("image_copy", $url ."/" . $file);
}
else {
print "ok<br/>";
flush();
}
}
}
//...
}
$this->generate_image_filenames() ... returns an array of file names for a product
$url ... the absolute url of the file to be downloaded
$file ... the target, where we want to copy the file to
error() ... logs errors
i wonder if someone has a quick solution for this - javascript i suppose would be one thing to look into (though i'd rather go out of its way).
my favorite solution would be a method i can simply invoke in the else{} path, which adds a string to the displayed info (or replaces the current info) - such as
// snip
else {
display_message($url . "... done");
}
// snip
thanks a bunch in advance!
rock on.