News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Random Image in Header

Started by yotoc, November 10, 2005, 08:04:47 PM

Previous topic - Next topic

yotoc

First off, seems search is down and I've browsed through pages and pages and can't find an answer to this. 

I recently moved from phpbb to smf and am trying to put the random images I used in the header of my old forums to the new.  I was using a perl script but it won't seem to work with smf.

Anybody have any suggestions?

bloc

For a perl script its hard to make it actually work in SMF..but doing it in php is not so hard. What did the perl script essentially do?

yotoc

It was pretty simple, not even sure why it was done in perl.  I just know it won't work with smf.

I figured I'd ask around here before going the php route.  Any idea how to do this?  If not, I'll work on it myself and just come crawling back here when I finally admit defeat.

bloc

:) no, I can help..what kind of images? how are they named? If they are named like xxx02.jpg its easier to setup a random function to generate a number..and simply display the image with that number in it.

If you have more categories/name styles, it can be done in 2 steps, first random category/name styles, then random image.

yotoc

No, just 10 images.  logo1 through logo10.jpg

Acf

#5
Make directory and put the images in it. Copy the code in your notepad and save it as index.php
Example of the code inaction:
**removed**
You can just add it as an image. Every load/reload the image changen to someting els.
Code for index.php:
<?php   

$handle 
opendir('.');   
while (
false !== ($file readdir($handle))) {   
    if (
$file != "." && $file != "..") {   
    
$ext=substr($file,-4);  
    if (
$ext == ".jpg" or $ext == ".gif" or $ext == ".png") {  
        
$images[count($images)] = $file;   
    }  
    }   
}  
closedir($handle);   


srand((double)microtime()*1000000);  

$key array_rand($images);  
$image $images[$key];  
$ext=substr($image,-4);  

header("Cache-Control: no-cache, must-revalidate");           // HTTP/1.1 
header("Pragma: no-cache");  
header("Expires: Sat, 20 May 1995 03:32:38 GMT");  

if (
$ext == ".jpg") {  
    
header("Content-type: image/jpeg");  
}  
else if (
$ext == ".gif") {  
    
header("Content-type: image/gif");  
}  
else if (
$ext == ".png") {  
    
header("Content-type: image/png");  
}  

readfile($image);  
?>
Sigh...

yotoc

Ran out of time to try this but will when I can.  Thanks a lot.

Advertisement: