Greetings all,
Could someone please review this code (found on an old thread) and tell me what's wrong? It returns a parse error on the last line. Thanks!
The basic idea is to choose a random file from a directory and include it in the page. If you have alternate code, I'm open to that as well.
<?php
//Specify the path to the files
$directoryPath="http://www.1-divorce.com/articles/";
if ($dir = @opendir("$directoryPath")) {
//Make sure it is not a directory, just a file
while (($file = readdir($dir)) !== false) {
//Add the file name to the array
if(is_file("$directoryPath$file")){
$fileArray[]="$file";
}
}
closedir($dir);
}
//Pick a random file name out of the array
$fileName=$fileArray[rand(0,count($fileArray)-1)];
//Get the file extension
$ext=explode(".",$fileName);
$ext=$ext[1];
//If it is an image, including the file will display gobbledy-gook
//So, we need to print the image.
if($ext=="gif" or $ext=="jpg"){
print("<img src=\"$directoryPath$fileName\">");
//if it is a file, just include it.
}else{
include("$directoryPath$fileName");?>