Random Pic php script
Posted: Fri Nov 19, 2004 2:50 pm
I've been usign the following php script for random sigs and avatars in vBulletin. It works fine for the defined image types, but I'd like to include small flash movies for avatars etc. The script seems to work fine outside of the forums, but doesn't parse the .swf in posts. Anyone have any idea's? Below is the script, notice that I've added the following line.
Here's the full script.
Any help would be greatly appreciated. Thanks in advance. 
Code: Select all
$extList['swf'] = 'application/x-shockwave-flash';Code: Select all
<?
// set image directory if '.' = image dir
$folder = '.';
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
$extList['swf'] = 'application/x-shockwave-flash';
// --------------------- END CONFIGURATION -----------------------
$img = null;
if (substr($folder,-1) != '/') { $folder = $folder.'/'; }
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
// If we have at least 1 image
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "You broke it!", $text_color);
imagepng ($im);
imagedestroy($im);
}
}
?>