Thor Erik
09-06-2006, 03:55 PM
this is the actual "image"
<?php
// the header saying that it's a php script :)
@header ('application/x-httpd-php');
// Name of your image directory
$mydir = "images";
// Make true random
srand( time() );
// Open image directory and put images in an array
if ($dir = @opendir($mydir)) {
? while (($file = readdir($dir)) !== false) {
if ( eregi( '.(jpg|gif)$', $file ) ) { $files[] = $file; }
? }
? closedir($dir);
}
// Find a random image
$file = $files[rand() % sizeof( $files )];
// Send headers for the random image
if ( eregi( '.jpg$', $file ) ) {
? header( "Content-Type: image/jpeg" );
} else {
? header( "Content-Type: image/gif" );
}
header( "Content-Length: " . filesize( $mydir."/".$file ) );
readfile( $mydir."/".$file );
?>
save this as image.php in a separte folder. (folder tree at the bottom)
Folder tree(names without extentions are folders):
*-root
|
*----avatar
? ?|
? ?*----image.php (main image file)
? ?|
? ?*----images (store the images of your choise here (.jpg and .gif)
how to:
to make it work on a forum;
the link must be similar to: http://www.yourdomain.com/avatar/image.php/image.gif (/image.gif to fool the forum, to belive that is a image and not a php script xD)
simple demo:
http://www.thor.p4h.biz/avatar/images.php/image.gif (for a forum)
http://www.thor.p4h.biz/avatar/images.php (dosen't work on a forum, but displayes the image ;))
if you don't manage to make it work, post here ;)
note: the one i use is the same code ;)(some tweaks that makes it more secure)
<?php
// the header saying that it's a php script :)
@header ('application/x-httpd-php');
// Name of your image directory
$mydir = "images";
// Make true random
srand( time() );
// Open image directory and put images in an array
if ($dir = @opendir($mydir)) {
? while (($file = readdir($dir)) !== false) {
if ( eregi( '.(jpg|gif)$', $file ) ) { $files[] = $file; }
? }
? closedir($dir);
}
// Find a random image
$file = $files[rand() % sizeof( $files )];
// Send headers for the random image
if ( eregi( '.jpg$', $file ) ) {
? header( "Content-Type: image/jpeg" );
} else {
? header( "Content-Type: image/gif" );
}
header( "Content-Length: " . filesize( $mydir."/".$file ) );
readfile( $mydir."/".$file );
?>
save this as image.php in a separte folder. (folder tree at the bottom)
Folder tree(names without extentions are folders):
*-root
|
*----avatar
? ?|
? ?*----image.php (main image file)
? ?|
? ?*----images (store the images of your choise here (.jpg and .gif)
how to:
to make it work on a forum;
the link must be similar to: http://www.yourdomain.com/avatar/image.php/image.gif (/image.gif to fool the forum, to belive that is a image and not a php script xD)
simple demo:
http://www.thor.p4h.biz/avatar/images.php/image.gif (for a forum)
http://www.thor.p4h.biz/avatar/images.php (dosen't work on a forum, but displayes the image ;))
if you don't manage to make it work, post here ;)
note: the one i use is the same code ;)(some tweaks that makes it more secure)