I have a website and I would like visitors to see a new image or flash (both would be even better) everytime they visit my site, this could give my site a fresh look. A radom image of flash choosen from 6 or 7. PHP would be the best option
I do this with ASP. I use a generic random function that randomly gives me a number between 1 and 7 and then I insert that random number in the image tag. Example image(3).jpg Name your images image1.jpg to image7.jpg Thats the way I do it. It should be easy to find a PHP random function. Hope this helps.
try this fuction and change the 100 to the number of images you have http://www.alt-php-faq.org/local/28/
FastByffalo, Thank you for your fast realy. I just don't understand what you mean. I can't code myself and am looking for a existing script
Don't have any off-hand, don't use PHP but hotscripts.com has always been a good source for me. I'm sure they have some prebuilt scripts.
Thanks alot FastBuffalo For other looking for such a thing, check http://www.hotscripts.com/Detailed/50693.html http://www.hotscripts.com/Detailed/11670.html http://www.hotscripts.com/Detailed/45123.html http://www.hotscripts.com/Detailed/30755.html I am going to try all 4. If anyone else knows one, please post it here. Thank you
Those four don't seem to do the job (for free) <?php $folder = '.'; $extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['jpeg'] = 'image/jpeg'; $extList['png'] = 'image/png'; $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 (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, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } } ?> Code (markup): This one does, but how can it do the same with flash files?
Seems complicated for something so easy, how many images are we talking about? If you name the files like the above poster suggests image0, image1, image2. The code length would be 5 lines.
I was wrong its 4 lines <?php $random_integer = rand(0,10); // Assumes you have images from image0 to image10 echo "<img src=\"http://www.domain.com/image", $random_integer, ".jpg\"></img>", ; //point to the correct domain/folder, this assumes .jpg but can be easily changed ?> Code (markup): If you use it, a link would be nice.
so that it'll display either an image or a flash file? Can you post your html code for displaying a regular flash file for your website. Different people use different html code for displaying swf files. Without knowing specifically what you are using. It'll look like this <?php $random_integer = rand(1,2); if (is_int($random_integer / 2)) { $random_integer = rand(0,10); // Assumes you have images from image0 to image10 echo '<img src="http://www.domain.com/image', $random_integer, '.jpg"></img>'; //point to the correct domain/folder, this assumes .jpg but can be easily changed } else { $random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10 echo 'insert html to generate your flash file here'; // Don't forget to incorporate $random_integer for the flash file number. } ?> Code (markup):
Here is my code for flash <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" id="Main" width="269" height="367"> <param name="movie" value="Main.swf"> <param name="bgcolor" value="#FFFFFF"> <param name="quality" value="high"> <param name="allowscriptaccess" value="samedomain"> <embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="269" height="367" name="Main" src="Main.swf" bgcolor="#FFFFFF" quality="high" swLiveConnect="true" allowScriptAccess="samedomain" ></embed> </object> Code (markup): So once I have put the code in a php file, how do I put the php file into my html page? Thank you
Hopefully you have php installed on your server. To place php into an html file is easy copy/paste the code I gave you into the html file your editing. Thats some of the power of php. This might work, if not we'll try something more blunt. <?php $random_integer = rand(1,2); if (is_int($random_integer / 2)) { $random_integer = rand(0,10); // Assumes you have images from image0 to image10 echo '<img src="http://www.domain.com/image', $random_integer, '.jpg"></img>'; //point to the correct domain/folder, this assumes .jpg but can be easily changed } else { $random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" id="Main" width="269" height="367"> <param name="movie" value="Main.swf"> <param name="bgcolor" value="#FFFFFF"> <param name="quality" value="high"> <param name="allowscriptaccess" value="samedomain"> <embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="269" height="367" name="Main" src="flash'; //assumes you named the flash file as flash echo $random_integer ,'.swf" bgcolor="#FFFFFF" quality="high" swLiveConnect="true" allowScriptAccess="samedomain" ></embed> </object>'; } ?> Code (markup):
Try this, and let me know what line if any you get errors for. <?php $random_integer = rand(1,2); if (is_int($random_integer / 2)) { $random_integer = rand(0,10); // Assumes you have images from image0 to image10 echo "<img src=\"http://www.domain.com/image", $random_integer, ".jpg\"></img>"; //point to the correct domain/folder, this assumes .jpg but can be easily changed } else { $random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10 echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\""; echo "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0\""; echo "id=\"Main\" width=\"269\" height=\"367\">"; echo "<param name=\"movie\" value=\"flash", $random_integer, ".swf\">"; echo "<param name=\"bgcolor\" value=\"#FFFFFF\">"; echo "<param name=\"quality\" value=\"high\">"; echo "<param name=\"allowscriptaccess\" value=\"samedomain\">"; echo "<embed type=\"application/x-shockwave-flash\""; echo "pluginspage=\"http://www.macromedia.com/go/getflashplayer\""; echo "width=\"269\" height=\"367\""; echo "name=\"Main\" src=\"flash", $random_integer, ".swf\""; echo "bgcolor=\"#FFFFFF\" quality=\"high\""; echo "swLiveConnect=\"true\" allowScriptAccess=\"samedomain\""; echo "></embed>"; echo "</object>"; } ?> Code (markup):
Now all I get to see it "; //point to the correct domain/folder, this assumes .jpg but can be easily changed } else { $random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10 echo ""; echo ""; echo ""; echo ""; echo ""; echo " Code (markup):
I think I got it working with this code, but this without image file and it cannot find the .swf file <?php $random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10 echo> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" id="Main" width="269" height="367"> <param name="movie" value="$random_integer".swf"> <param name="bgcolor" value="#FFFFFF"> <param name="quality" value="high"> <param name="allowscriptaccess" value="samedomain"> <embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="269" height="367" name="Main" src="flash'; //assumes you named the flash file as flash echo $random_integer ,'.swf" bgcolor="#FFFFFF" quality="high" swLiveConnect="true" allowScriptAccess="samedomain" ></embed> </object> Code (markup):