Re: List of files?
| From: | Brian C. Doyle | Date: | Tue, 21 Aug 2001 12:44:18 +0000 |
| Subject: | Re: List of files? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-63689@lists.php.net to get a copy of this message | ||
Here is some code that I use to do what you wanted and attach is the files for the folders.
This uses javascript that works well with Internet Explorer and creates sublist that appear in the folder.
<?
error_reporting (E_ALL ^ E_NOTICE);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title><style> <!-- #foldheader{cursor:hand ; font-weight:bold ; list-style-image:url(fold.gif)} #foldinglist{list-style-image:url(list.gif)} #file{list-style-image:url(list01.gif)}
A:link { color: #8000ff; }
A:visited { color: #000080;background:#a9a8bd }
A:active { color: #0080ff;font-weight:bold;background:#bcbbcc}
A:hover { color: #0080ff;font-weight:bold;background:#FFFFFF}
//-->
</style>
<script language="JavaScript1.2">
var head="display:''"
img1=new Image()
img1.src="fold.gif"
img2=new Image()
img2.src="open.gif"
function change(){
if(!document.all)
returnif (event.srcElement.id=="foldheader") {
var srcIndex = event.srcElement.sourceIndex
var nested = document.all[srcIndex+1]
if (nested.style.display=="none") {
nested.style.display=''
event.srcElement.style.listStyleImage="url(open.gif)"
}
else {
nested.style.display="none"
event.srcElement.style.listStyleImage="url(fold.gif)"
}
}
}
document.onclick=change
</script>
</head>
<?
$dir="../";
$handle=opendir($dir);
while ($file = readdir($handle)) {
$local="$dir/$file";
if (is_dir($local)) {
if ($file != "." && $file != "..") {
$dirArray[] = $file;
}
}
elseif(is_file($local)){
$ext=substr($file,$strlen-4,4);
if ($ext==".jpg"||$ext=="jpeg"||$ext==".JPG"||$ext=="JPEG"||$ext==".gif"||$ext==".GIF"||$ext=="png"||$ext=="PNG"){
$imageinfo_Array[]=$file;
}
elseif ($file!="." && $file!=".."){
$fileinfo_Array[]=$file;
};
};
};
closedir($handle);
asort($dirArray);
asort($imageinfo_Array);
asort($fileinfo_Array);
?>
<BODY BGCOLOR=#ffffff TOPMARGIN=10 LEFTMARGIN=5>
<ul>
<?
$dirArray;
while (list($key,$value) = each($dirArray)) {
$dir_info=base64_encode($value);
$subdir="../$value";
?>
<li id="foldheader"> <?$dirinfo=explode("-",$value);while (list($key,$info)=each($dirinfo)){echo ucfirst($info)," ";};?>
<?
$open_subdir=opendir($subdir);
$file_info_Array=array();
while ($file = readdir($open_subdir)) {if (is_dir($img_file)) {}
else{
$ext=substr($file,$strlen-4,4);
if ($ext==".jpg"||$ext=="jpeg"||$ext==".JPG"||$ext=="JPEG"||$ext==".gif"||$ext==".GIF"||$ext=="png"||$ext=="PNG"){
$image_info_Array[]=$file;
}
elseif ($file!="." && $file!=".."){
$file_info_Array[]=$file;
};
};
};
closedir($open_subdir);
natcasesort($file_info_Array);
natcasesort($image_info_Array);
?> <?echo $count?></li>
<ul id="foldinglist" style="display:none" style=&{head};>
<?
while (list($key,$value) = each($file_info_Array)) {
?>
<LI id="file"> <A HREF="edit.php?dir_info=<?echo $subdir?>&file=<?echo $value?>" TARGET="right" ><?echo $value;?></A></LI><? }; ?> <? while (list($key,$value) = each($image_info_Array)) { ?>
<LI> <?echo $value;?></LI><? }; ?></ul> <? } while (list($key,$value) = each($fileinfo_Array)) { ?>
<LI id="file"> <A HREF="edit.php?dir_info=../&file=<?echo $value?>" TARGET="right" ><?echo $value;?></A></LI><? }; while (list($key,$value) = each($imageinfo_Array)) { ?>
<LI id="foldinglist"> <?echo $value;?></LI><? }; ?></ul> <DIV ALIGN=center> <TABLE> <TR>
<TD COLSPAN="2" ALIGN="center"><A HREF="new.php?new=yes" TARGET="right" ><B>New Page<B></A><TD></TR> <TR>
<TD COLSPAN="2" ALIGN="center"><A HREF="index.html" TARGET="_parent" ><B>Main Page<B></A><TD></TR> </TABLE> </DIV> </BODY> </HTML> At 01:26 PM 8/21/01 +0100, Seb Frost wrote:
OK so I'vebeen reading about reading and writing to/from files, but what I want to do is (I think) simpler than this. Basically I want to look at a directory and be able to get a list of all subdirectories and then a list of the files in each directory. Can someone give me a hint? cheers.... - seb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
Attachment: [application/zip] filelist.zip