News:

Wondering if this will always be free?  See why free is better.

Main Menu

Random Avatar Script

Started by Meriadoc, August 03, 2003, 01:32:29 AM

Previous topic - Next topic

Tyris

well, the php script itself is hosted on your OWN server, so it can only do damage to that one, and not places the image is viewed at.

I'm pretty sure its a .php file that you just display with [img*]file.php[/img*] (without * of course)
to my knowledge, the browser tries to do display the 'image' located there, the server then runs the php script and creates the php output.
for a random avatar all you need to do is have the script randomly select an avatar and then display that.

Cerberus

I'm using [Unknown]'s code
<?php
ob_start
('ob_gzhandler') && ($p = '/web/htdocs/site29/home/avatars') && ($d = opendir($p));
while(
false !== ($f = readdir($d)))
 
stristr($f, 'jpg') || stristr($f, 'gif') ? ($m[] = array($f, (stristr($f, 'jpg') ? 'jpg' : 'gif'))) : 0;
closedir($d) && header('Content-Type: image/' . $m[($r = rand(0, count($m) - 1))][1]) && print file_get_contents($p.$m[$r][0]);
?>

the script is placed in /avatars but it isn't working: I get a 500 error. Any thoughts?
Best Regards, Cerberus
YaBB Gold -> YaBB 1.1 -> YaBB SE (YaPP -> PfaBB) -> SMF
Pocket PC Russia

BigMike

Try replacing:

ob_start('ob_gzhandler') && ($p = '/web/htdocs/site29/home/avatars') && ($d = opendir($p));

With:

ob_start('ob_gzhandler') && ($d = opendir("."));

Cerberus

It isn't working, but I've found another script, which works well on my server
<?php
/*
-------------------------------------------------------------
|MD Random Image Generator                                  |
|Version 1.0.0                                              |
|This program is Copyright (c) Matthew Dingley 2003         |
|For more help or assistance go to MD Web at:               |
|www.matthewdingley.co.uk                                   |
|For information on how to install or for basic licence     |
|information, view below                                    |
|                                                           |
|This program is not to be used on a commercial site without|
|a commercial licence. Go to www.matthewdingley.co.uk for   |
|more information.                                          |
|                                                           |
|To install, just enter in the directory name that you store|
|the images in to the variable below named $dir. Upload any |
|images to that folder to have them randomly displayed.     |
|                                                           |
|You can also edit the variable $pattern if you know what   |
|you are doing.                                             |
|                                                           |
|To display the random image on your web page, you can      |
|either copy and paste all of this code into the page where |
|you want it or you can include it by putting in the        |
|following code into the page where you want the image:     |
|<?php include "image.php"; ?>
                              |
-------------------------------------------------------------
*/
$dir=opendir("/home/you/public_html/folder/");
//This is the directory route to the folder
$directory="";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on

$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);

//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>

:)
Best Regards, Cerberus
YaBB Gold -> YaBB 1.1 -> YaBB SE (YaPP -> PfaBB) -> SMF
Pocket PC Russia

Overseer

damn this thread old!


\/ well ya can see my randomise sig banner works! \/


need more entries though..

evirvana

Okay, I'm new to all this, and I have never made PHP script in my life so can someone please explain in an easy way all the steps to making a random sig image? I have all the pics I need, and they are all uploaded, I just need to know how to make the script. Thanks for the help.

Vinoth

this would consume more BW in total,

btter to have an single avatar to display
Vinoth And Sachin ( SpecHackers Team )
The Best  Way to Help Poor Is not Becoming One Of Them.

Chris Cromer

#27
Well as long as you don't use extremely huge images then it will be fine. :P

I have over 400 something avatars in rotation on plenty of big sites including sites like gamespot.com, this site, my own sites, etc. And my site only gets around 1GB of bandwidth usuage a month, and that includes all the downloads of utilities, games, images, movies, etc. So my point is, it doesn't use that much bandwidth. :P
Chris Cromer

"I was here, here I was, was I here, sure I was" - The little voice in my head.

The Mole

Quote from: evirvana on July 02, 2004, 10:03:32 PM
Okay, I'm new to all this, and I have never made PHP script in my life so can someone please explain in an easy way all the steps to making a random sig image? I have all the pics I need, and they are all uploaded, I just need to know how to make the script. Thanks for the help.

I'll help you out so long as you have your own website, with php, already.

-the mole

Kerux

Quote from: <? Piranha($fx); ?> on August 20, 2003, 07:07:34 PM
My updated script rocks! And best yet: It's on Hotscripts! BEAT THAT! 8) :P

but unfortunately it can no longer be downloaded
I am, I saw, I programmed.

Owdy

Does anyone have good script what supports png jpg and gif ?

yes i know this topic is old :P
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

DavidCT

It looks like Cerberus's code (Reply #23) does, no?


$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";



Blah blah


Advertisement: