TinyPortal
Development => Block Codes => Topic started by: gerrymo on October 22, 2006, 01:50:18 PM
This script will display a random file (txt, html, htm, php) from a single directory.
<?php
$txt_array = Array();
$my_dir = "XXXXX/"; //Replace it with your directory (don't delete the slash)
if ($dir = @opendir("$my_dir")) {
while (($file = readdir($dir)) !== false) {
if ($file != "." && $file != ".." && !is_dir($my_dir.$file))
{
/* echo $my_dir.$file."<br>"; DEBUG show file list */
$txt_array[] = $file;
}
}
closedir($dir);
}
$random_number=rand(0, count($txt_array)-1);
$random_txt=$txt_array[$random_number];
//This code includes the text file file
include($my_dir.$random_txt);
//This code show a random image
// echo "<img src=\"".$my_dir.$random_txt."\" border=\"0\" alt=\"\">";
?>
Change XXXXX to the directory you want to display files from.
Create a new php file using the above code and upload to your server.
Make a php block and and use an include to call the file you just made into a block using
include('FULL URL/filename.php');
You're now good to go. Each time the page is loaded, it will display a random file from the directory you specified.
nice :D great job!!
I do have to admit, It was sent to me by e-mail, I didnt write it.
no problem :up: its the sharing that counts more than anyhing else :D
Hi,
I can't get this to work after upgrading to TP 9.7.1 and SMF 1.1.1. Randomfile works great as stand alone but SMF/TP wont include as before the upgrade.
Anyone know a fix for this?