Shoutbox

PHP Random Avatar Cache - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP Random Avatar Cache (/showthread.php?tid=40977)

PHP Random Avatar Cache by user27089 on 03-23-2005 at 08:07 AM

code:
<?php
$dir = "imgs"; //The folder where all the images are kept
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
srand( (double) microtime()*1000000 );
$randnum = rand(0, $filesnum - 1);
header("Location: " . $dir . "/" . $files[$randnum]); //redirects the browser to a random file, allowing it to cache
?>


the images automatically go to the cache, I don't want this to happen... Can somebody edit the code accordingly please? So that it doesn't cache...

:$Not good with PHP:$.
RE: PHP Random Avatar Cache by fluffy_lobster on 03-23-2005 at 11:44 AM

Try:

code:
<?php
$dir = "imgs"; //The folder where all the images are kept
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
srand( (double) microtime()*1000000 );
$randnum = rand(0, $filesnum - 1);
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Location: " . $dir . "/" . $files[$randnum]); //redirects the browser to a random file, allowing it to cache
?>

RE: PHP Random Avatar Cache by .Roy on 03-23-2005 at 11:58 AM

flufffy what script should i rather use?
I am looking for one that makes my images go one my one by their order. Basically so i can go through all the images without going through  one image twice....
Which one is good for what i need Fluffy

This:

<?php
$dir = "imgs";
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
srand( (double) microtime()*1000000 );
$key = array_rand($files);
readfile($dir . "/" . $files[$key]);
?>

Or the one u just posted which is this:

<?php
$dir = "imgs"; //The folder where all the images are kept
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
srand( (double) microtime()*1000000 );
$randnum = rand(0, $filesnum - 1);
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Location: " . $dir . "/" . $files[$randnum]); //redirects the browser to a random file, allowing it to cache
?>


RE: PHP Random Avatar Cache by -dt- on 03-23-2005 at 12:05 PM

neither will work because they both do random , how are your images laid out are they like

"comic1.png"
"comic2.png"
"comic2.png"

because if they are I can write a nice script for it but basicly just need to tell me or someone else how each file is stored


RE: PHP Random Avatar Cache by .Roy on 03-23-2005 at 12:09 PM

no.. Its

strip.1.gif
strip2.gif
strip3.gif


So on..