Wednesday, January 20, 2010

PHP list Directory and File


Script below to list directory and file using function opendir(); This is a simple code to define directory name, file name, object type and also file extension.


<?php

$dirname = "radio"; // set directory name
$dir = opendir($dirname); // open directory

while(false != ($file = readdir($dir))){

if(($file != ".") and ($file != "..")){ // prevent list hidden directory
echo filetype($dirname."/".$file); //print object type ( dir. or file )
echo "--ext. name:".pathinfo($file, PATHINFO_EXTENSION)."--"; // print file extention
echo("<a href='".$dirname."/$file'>$file</a> <br />"); // print file and the url

}

}

?>


You can customize to be photo, video, music and also others file gallery.

Folder or directory as the category and file in the directory as the item of the category.

For video you can download the plug-in form FLV JW player( posted in article before ) .

Example video listing.


Example file listing


Need a simple script? download here .

have fun!!!


- Created By Thegreatestpost.blogspot.com