Ok, one of the most requests I get is a script for random signature images.
The second most frequent request I get is for random avatar images
Well lets cover the first one
As always this script can be downloaded here
Note for internode customers: if you’re using your node space it’s important to chmod 0755 you’ll need to check with your ftp client on how to do this. If you don’t you will get an ‘Internal Server Error’
One tip I can give you tho is to use the console ftp client included with windows to chmod after you’ve uploaded the file.
Example for Internode users
ftp users.on.net
cd /pathtoscript/
lit site chmod 0755 randomimage.php
That should fix your ‘Internal Server Error’
<?php
/* PHP Rotate 1.00
By Freman
--------------------------------------------------
Due to the large number of requests I get for
this (and similar) script, I'm making it availible
for all to see and use
Configuration Options:
$PathToImages = The path to your image files
Example:
$PathToImages = "images/"
*/
$PathToImages='images/';
// !!!!! Don't edit below here or I won't smack you.!!!!!
// Open a directory object
$Dir = dir($PathToImages) or die("Oops, it's broken - are you sure you've got the right PathToImages?\n");
// Read the dir
while (false !== ($DirEntry = $Dir->read())) {
// Look for images
if (preg_match('/\.(jpe?g|gif|png)$/',$DirEntry)) {
// Keep track of the images we've found
$Images[] = $DirEntry;
}
}
// Get a random image
$Image = $Images[array_rand($Images,1)];
if ($fp = fopen("$PathToImages/$Image",'rb')) {
// Helps to know how big the file is we want to read
$FileSize = filesize("$PathToImages/$Image");
// Get the file extension
preg_match('/\.(jpe?g|gif|png)$/',strtolower($Image),$Match);
// Work out what our content type is
if (in_array($Match[1],array('jpg','jpeg'))) {
$ContentType = 'image/jpeg';
} elseif (in_array($Match[1],array('gif','png'))) {
$ContentType = 'image/'.$Match[1];
}
// Print out some headers to satisfy the browsers
header("Content-type: $ContentType");
header("Content-length: $FileSize");
// Print out some headers to keep the random image from being cached
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Output our image (Long process huh)
print fread($fp,$FileSize);
// Always clean up after yourself
fclose($fp);
}
?>
Now to make it work as an avatar you need to trick apache into serving up your php script as a jpg/gif or png file due to the way the forums limit the extensions on files.
Best way to use this file is to make it htaccess.txt on your windows machine, upload it, then rename it to .htaccess
RewriteEngine on
RewriteRule randomimage.jpg /~<YOUR USERNAME>/<PATH>/randomimage.php [L]