if($file != '.' && $file != '..')to
if($file != '.' && $file != '..' && file != 'index.php')
| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Posted 25 August 2006 - 04:30 AM
echo "<a href='$path$narray[$i]'>$narray[$i]</a><br/>";and still be sufficient. As long as $path is correct you do not need char(34) since a single quote will suffice.
$filename = str_replace(".htm", ".", $narray[$i]);
OR$filename = str_replace(".htm", "", $narray[$i]);
Place this right before echo (in my case) solved my issue. The problem was that the replacing string had to have a value. I left it as just " " and it wasn't working.
Posted 05 March 2009 - 05:21 PM
Thanks itssami, for your great code, I just need to add a little thing, I would like to restrict the list to the .Html files only, I mean, if I have a directory with let say .Html, .Txt and .Jpg files but I only want to list .Html ones, is there a way to do this?
Posted 15 November 2009 - 06:09 PM
any chance to make this code to sort by date, or time so I can display the files in descending order from the oldest to the newest.??
<?$path = " ";$narray=array();$dir_handle = @opendir($path) or die("Unable to open $path");Echo "Directory Listing of $path<br/>";$I=0;While($file = readdir($dir_handle)){ if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { //echo "<a href='$path/$file'>$file</a><br/>"; $narray[$I]=$file; $I++; }}Rsort($narray);
for($I=0; $I<sizeof($narray); $I++){Echo "<a href=".Chr(34).$path.$narray[$I].Chr(34).">".$narray[$I]."</a><br/>";
}
//closing the directoryClosedir($dir_handle);?>
thanks in advance
Posted 12 May 2011 - 04:31 AM
<?php
//$zit = 0;
//$zit = $zit + 1;
//-$zit
function ListFolder($path)
{
$pdfOrderarray=array();
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
$i=0;
//display the target folder.
echo ("<li><img alt='FOLDER' src='../../../images/Folder.png'> $dirname\n");
echo "<ul>\n";
while (false !== ($file = readdir($dir_handle)))
{
if($file!="." && $file!="..")
{
if (is_dir($path."/".$file))
{
//Display a list of sub folders.
ListFolder($path."/".$file);
}
else
{
//Display a list of files.
// echo "<img alt='PDF' src='../images/PDF.png'> $file<br/>";
$pdfOrderarray[$i]=$file;
$i++;
}
}
}
//closing the directory
closedir($dir_handle);
sort($pdfOrderarray);
for($i=0; $i<sizeof($pdfOrderarray); $i++)
{
echo "<img alt='PDF' src='../../../images/PDF.png'> $pdfOrderarray[$i]<br/>";
}
echo "</ul>\n";
echo "</li>\n";
}
?>
Posted 12 May 2011 - 07:20 PM
<?php
function ListFolder($path)
{
$narray=array();
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
$i=0;
//display the target folder.
echo ("<li><img alt='PDF' src='../images/Folder.png'> $dirname\n");
echo "<ul>\n";
while (false !== ($file = readdir($dir_handle)))
{
if($file!="." && $file!="..")
{
if (is_dir($path."/".$file))
{
//Display a list of sub folders.
ListFolder($path."/".$file);
}
else
{
//Display a list of files.
// echo "<img alt='PDF' src='../images/PDF.png'> $file<br/>";
$narray[$i]=$file;
$i++;
}
}
}
//closing the directory
closedir($dir_handle);
sort($narray);
for($i=0; $i<sizeof($narray); $i++)
{
echo "<img alt='PDF' src='../images/PDF.png'> $narray[$i]<br/>";
}
echo "</ul>\n";
echo "</li>\n";
}
?>
Edited by jibberweed, 12 May 2011 - 07:21 PM.
Posted 12 May 2011 - 11:02 PM
<?php
/* Rendering */
function list_dir($path)
{
$items = get_sorted_entries($path);
if (!$items)
return;
foreach($items as $item)
{
if ($item->type=='dir')
{
echo ("<li><img alt='PDF' src='../../../images/Folder.png'>".$item->entry."\n");
echo "<ul>\n";
list_dir($item->full_path);
}
else
{
echo "<img alt='PDF' src='../../../images/PDF.png'> ".$item->entry."<br/>";
}
}
echo "</ul>";
echo "</li>\n";
}
/* Finding */
function get_sorted_entries($path)
{
$dir_handle = @opendir($path) ;
$items = array();
while (false !== ($item = readdir($dir_handle)))
{
$dir =$path.'/'.$item;
if ( $item == '.' || $item =='..' )
continue;
if(is_dir($dir))
{
$items[] = (object) array('type'=>'dir','entry'=>$item, 'full_path'=>$dir);
}
else
{
$items[] = (object) array('type'=>'file','entry'=>$item, 'full_path'=>$dir);
}
}
closedir($dir_handle);
usort($items,'_sort_entries');
return $items;
}
/* Sorting */
function _sort_entries($a, $B)
{
return strcmp($a->entry,$b->entry);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
<title>TITLE</title>
<link rel="stylesheet" href="../jquery.treeview.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script src="../lib/jquery.cookie.js" type="text/javascript"></script>
<script src="../jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript" src="demo.js"></script>
</head>
<body>
<div id="treecontrol">
<a title="Collapse the entire tree below" href="#"> Collapse All</a> |
<a title="Expand the entire tree below" href="#"> Expand All</a> |
<a title="Toggle the tree below, opening closed branches, closing open branches" href="#">
Toggle All</a>
</div>
<ul id="red" class="treeview-red">
<?php
list_dir("directory you want to search");
?>
</ul>
<hr />
</body></html>
Edited by jibberweed, 12 May 2011 - 11:03 PM.
Posted 09 December 2011 - 07:23 AM
itssami, on 01 May 2006 - 11:30 AM, said:
<?$path = "";$dir_handle = @opendir($path) or die("Unable to open $path");echo "Directory Listing of $path<br/>";while($file = readdir($dir_handle)) { if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { echo "<a href='$path/$file'>$file</a><br/>"; }}//closing the directoryclosedir($dir_handle);?>

0 members, 1 guests, 0 anonymous users