search
top

Page Redirect

I have written a script for getting the files list from directory and redirecting the page on selecting option from the select box.

So you will get the script for fetching all the files from current directory and redirecting page on selection.

<h>Please select option</h>
<?php
$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; //current directory physical path

$dir_handle = @opendir($path) or die("Unable to open $path"); //using the opendir function

list_dir($dir_handle,$path);

function list_dir($dir_handle,$path)
{
    // print_r ($dir_handle);
    // form is not necessary
    echo "<form name='frm'>
    <select onchange='javascript:location.href=this.value' name='filelist'>";
    echo "<option value='' selected='selected'>----Select----</option>";
    //running the while loop
    while (false !== ($file = readdir($dir_handle))) 
    {
        $dir =$path.'/'.$file;
        if(is_dir($file)==false) //for omitting directory from listing
        {
	        if($file != '.' && $file !='..')
	        {
	        	 $f = str_replace('.php','',$file); //for removing extension
	                 echo "<option value='$file'>$f</option>";
	        }
        }
    }   
    echo "</select></form>";

    //closing the directory
    closedir($dir_handle);   
}
?>

Leave a Reply

top