Forum Moderators: coopster

Message Too Old, No Replies

Directory Listing

         

MrAndron1

4:51 am on Jul 14, 2007 (gmt 0)

10+ Year Member



I can see all the files in a directory but I can't see any folders. I nee to dee both the folders and files. Would you please help me. Here is the code. (it's not mine, I'm just using it).. Thanks in advance.

# Read current directory.

#------------------------

$d = dir(".");

while (false!== ($file = $d->read())) {

if ($file!= "." && $file!= "..") {

# Get all the file attributes.

#-----------------------------

$size = filesize($file);

$type = filetype($file);

$ext = strrchr($file,'.');

$modified = stat("$file");

$displayname = str_replace (strrchr ($file, "."), "", $file);

# If it is a file (not a directory) and the file extention is in $display_list..

#-------------------------------------------------------------------------------

if (($type == file) && (preg_match ("/$ext/i", $display_list))) {

# Format the Dispayed filename.. replace underscore with a space

# and Change each word to start with an upper case letter.

#---------------------------------------------------------------

$displayname = str_replace("_"," ",$displayname);

$displayname = strtolower($displayname);

$displayname = ucwords($displayname);

$filedate = date("m-d-y",$modified[9]);

IndiaMaster

7:14 am on Jul 14, 2007 (gmt 0)

10+ Year Member



Hi,

Try the following code:

if ($fileHandler = opendir('upload'))
{
if(false == ($file = readdir($fileHandler)))
{
echo("<div class=heading>No CDR files are available for importing.</div>");
}
else
{
echo("<table width=80% border=1 cellpadding=1 cellspacing=0>");
echo("<tr><th width=10%>Sl. No.</th><th width=45%>File Name</th><th width=25%>File Size (Bytes)</th><th>Import</th>");
}
while (false!== ($file = readdir($fileHandler)))
{
if ($file!= "." && $file!= "..")
{
$fileurl=getcwd()."/upload/".$file;
//$fileurl="http://www.example.com/orion/cdr/att"."/upload/".$file;

if($i%2==0)
echo("<tr class=even onmouseover=changeclass('even',$i) onmouseout=changeagain('even',$i) id=even".$i."><td class=bodytext>".$i."</td><td class=bodytext>".$file."</td><td class=bodytext>".filesize($fileurl)."</td><td><a href=import_cdr_to_temp.php?filepath=$fileurl&file=$file>Import</a></td></tr>");
else
echo("<tr class=odd onmouseover=changeclass('odd',$i) onmouseout=changeagain('odd',$i) id=odd".$i."><td class=bodytext>".$i."</td><td class=bodytext>".$file."</td><td class=bodytext>".filesize($fileurl)."</td><td><a href=import_cdr_to_temp.php?filepath=$fileurl&file=$file>Import</a></td></tr>");
$i++;
}

}
closedir($fileHandler);
}

[edited by: eelixduppy at 9:30 am (utc) on July 14, 2007]
[edit reason] example.com [/edit]