Endless Paradigm

Full Version: random avatar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
i want one

just need to know how to do it



so zing, goshi, dasme, sparker
hows it done
ooops don't look in that section much :embarrassed:


thanks zing



ummm i still don't get that little tut you posted

where do i copy and paste it to?
This needs to be saved in notepad as a .php file. Then you just upload it to a webhost.

Actually the script zing made is very different from the one I have =/
^^ thought it was in notepad



hmmm what does yours look like
mind posting?

PHP Code:
<?php
/*
How to use:
1. Place suitable images in the same folder as the script resides.
The images should have a .jpg, .gif or a .png ending.

2. Copy the source of this script in a textfile, rename it avatar.php
(or any other name, as you please) and save it in the same directory as the images.

3. Call the script by appending a random name with the filetype ending.
Example:
http://www.fungifun.org/rotate/avatar.php/example.jpg

avatar.php is the name of the script

example.jpg is a random name, you could also use asasd.jpg or qwfpoa.jpg, the name doesn't matter,
what is important is the ending. The ending determines which files from the folder are used.
So, if you use example.gif, then the gif files in this folder will be used.
*/

$filetype = end(explode(".",$_SERVER['REQUEST_URI']));
if($filetype != "jpg" && $filetype != "gif" && $filetype != "png") exit;
if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && stristr($file, ".".$filetype)) $files[]=$file;
   }
   closedir($handle);
}
if ($files) {
    $imagenr = rand(0, sizeof($files)-1);
    if($filetype == "jpg") $filetype = "jpeg";
    $fp = fopen($files[$imagenr], 'rb');
    header("Content-Type: image/$filetype");
    header("Content-Length: " . filesize($files[$imagenr]));
    fpassthru($fp);
    exit;
}
?> 


If you add the lines

PHP Code:
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: image");


On the top of the script you can remove caching which makes the thing much faster. So in the end this script will always best ZiNgA's =P

^^That one's probably better.

I'm not very good at PHP.
Its better since you don't have to manually type each image's name over and over.
Oh yes, just a note. Make sure all images are the same size when using it otherwise it'll end up stretched and it'll look ugly.

You don't want to be in the same situation Sparky was stuck in at first.
testing....
[Image: ?action=view&amp;file=avatar.php]
[Image: ransig.php]
[Image: avatar.php]

mmzz.. failed..... dunno what im doin wrong
Pages: 1 2 3
Reference URL's