Undead Fred, question - http://www.mmcafe.com/ Forums


Original message (1794 Views )

Sensenic
1407th Post



user profileedit/delete message

Red Carpet Executive Member




"Undead Fred, question" , posted Tue 13 Dec 06:17post reply

How was that thing about random images in av or tag done?





Deidara. I just loved that face. XD

Listen to them - the children of the night. What music they make! Dracula

Replies:

Undead Fred
2585th Post



user profileedit/delete message

Platinum Carpet V.I.P- Board Master





"Re(1):Undead Fred, question" , posted Tue 13 Dec 09:29post reply

quote:
How was that thing about random images in av or tag done?

I had asked around here a while back on how to do it... I think CharlesProphony was the one that posted this code:

<?php

//uberRandom Image Script,
//by Ryan Lukasik (ryan@uberpolak.tk), Jan. 12, 2003
//Free to use, just please leave this block intact.
//Call this script with <IMG SRC="whateveryousavethisas.php">

//"images.dat" will contain the name of each image file
$imgs = file("images.dat");

header("Location: " . $imgs[rand(0,sizeof($imgs) - 1)]);

?>

Open Notepad or some other simple text program and paste this in. Save it as "randimg.php", then create another file called "images.dat", where you'll place all of the filenames for the pictures you want randomized. Then place them in a directory on a server with the images that you want randomized and (provided the server supports PHP), it should work just fine. You'll link directly to the PHP file in for avatar or tag in your profile here.

As an example, this is how mine works: I made a directory called "tags" or something like that, opened Notepad, dropped in the code and saved it to "randimg.php". Then I made another file with just "undeadtag16.gif" up to "undeadtag19.gif" or whatever I called the files listed out and saved that as "images.dat" in the same directory as the randimg.php file. Then I put randimg.php, images.dat, and all of the tags together in the same folder online and put the link to the PHP file as the source for my tags here at the Cafe. Let me know if you try it and have any problems.





CharlesProphony
15th Post



user profileedit/delete message

New Customer

"Re(2):Undead Fred, question" , posted Wed 14 Dec 00:16post reply

I gave another code that reads the directory, without the need of another file indicating the list of images, but I got to use this script in other forums and some forum types(phpbb, iB, etc) doesn't accept avs or signs using different extensions other than jpg, gif, png... thus refusing the .php script or giving errors, then I came with this thing I've read before somewhere and created a dir called "blablabla.gif" and put the script in and named it as index.php... with some tweaking like indicating the type of the file with a new header and voilá! it works!
the code :


<?php
//change "$dir_imgs" to the name of directory where your images are
$dir_imgs="./imgs/";
$dir_handler = @opendir($dir_imgs);
//this part will read the directory
while ($file = readdir($dir_handler)) {
if ($file!="." && $file!="..") {
$data[]=$file;
}
}
closedir($dir_handler);

//the next piece of code detects the type of image looking at the extension... nothing more... well, just more lazyness :P
switch (substr($data[array_rand($data)], -3,3)) {
case "gif" :
$imgtype=="gif";
break;
case "jpg" :
$imgtype=="jpeg";
break;
case "jpeg" :
$imgtype=="jpeg";
break;
case "png" :
$imgtype=="png";
break;
}
//the header that will redirect the browser to the random file in the "$dir_imgs" directory
header("Content-type: image/".$imgtype);
header("Location: ./".$dir_imgs."/".$data[array_rand($data)]);
?>


now some explanations about the code...
because of the name of the directory ("blablabla.gif") some browsers may get somewhat crazy with the type of images(like "why it's identified as a gif and read as a jpeg?") but as I tested in the firefox, nothing gone bad...
if you have any problems or questions, just post here, I'm entering every day... just honouring my fame as a lurker





just improving my english...

Sensenic
1408th Post



user profileedit/delete message

Red Carpet Executive Member




"Re(3):Undead Fred, question" , posted Wed 14 Dec 02:22post reply

oh, thanks a lot, you both.

But, after testing, I learned that my server doesn't even have php...

Ah, Timofónica, how I love thee... u_u;





Deidara. I just loved that face. XD

Listen to them - the children of the night. What music they make! Dracula

Sensenic
1413th Post



user profileedit/delete message

Red Carpet Executive Member




"To Charles Prophony" , posted Fri 16 Dec 05:48post reply

A little bird told me you like that Breda character, from Fullmetal Alchemist...

Have you read the manga? In case you haven't, I certainly advice you to do so, since it's really, really great (see me tag).
Plus you have at least one Breda pwning Ed scene...





Deidara. I just loved that face. XD

Listen to them - the children of the night. What music they make! Dracula

CharlesProphony
18th Post



user profileedit/delete message

New Customer

"Re(1):To Charles Prophony" , posted Fri 16 Dec 11:24post reply

quote:
A little bird told me you like that Breda character, from Fullmetal Alchemist...

Have you read the manga? In case you haven't, I certainly advice you to do so, since it's really, really great (see me tag).
Plus you have at least one Breda pwning Ed scene...


yes, I read the manga, plus now I got a reseller here in brazil to buy the series...
and in the free time I'm training some parts of my drawing style to draw some extra art for breda... he's a distinct character and I kinda liked him from the very first I saw him...





just improving my english...