Reply to Re: Get list of files in a specified folder on server

Your name:

Reply:


Posted by MikesBrain on 10/12/05 18:29

On Wed, 12 Oct 2005 01:56:35 GMT, "David" <right@dd.com> wrote:

>Hi All,
>
>I'm new to PHP and am trying to get the file contents of a folder. I have
>this code below but it is failing. Can a keen eye spot where I am going
>wrong?
>
>If not could you point me to a tutorial or the like?
>
>Thanks, David
>
>
><?
> session_start();
> session_register("imagecount_session");
> session_register("imagepath_session");
>?>
>
><?
>ListFolderContents($DOCUMENT_ROOT.$_GET["folder"]);
>function ListFolderContents($path)
>{
> extract($GLOBALS);
>
>
>$fs=$CreateObject["Scripting.FileSystemObject"]
>$folder=$fs->GetFolder $path);
>$imagecount_session=$folder->Files.$Count;
>foreach ($folder Files as $item)
> {
>
> $i=$i+1;
> $url=MapURL($item->path);
> session_register("iCount".$i);
>${"iCount".$i."_session"}=$item->Name;
> } return $function_ret;
>}
>for ($j=1; $j<=$imagecount_session; $j=$j+1)
>{
> $a[$j]=${"iCount".$j."_session"};
>
>}
>
>$s=$Join[$a][","];
>function MapURL($path)
>{
> extract($GLOBALS);
>
> $rootPath=$DOCUMENT_ROOT."/";
> $url=substr($path,strlen($path)-(strlen($path)-strlen($rootPath)));
> $MapURL=str_replace("\","/",$url);
> $imagepath_session=$MapURL;
> return $function_ret;
>}
>?>
>
>
I came across this some time ago and put it on my server, where it seems to
do the business; no doubt personal improvements can be made to it all over
the place.

<?
print("<table width=780 cellspacing=0 cellpadding=0 border=0><tr><td>");
print("Please be patient - you can sometimes be downloading a
<strong>lot</strong> of data.
<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entries without an
extension (the bit after the \" . \") are directories.<br>&nbsp;");
print("</td></tr></table>");
print("<table width=770 align=center cellspacing=0 cellpadding=0
border=0><tr><td>");
$open=opendir (".");
while ($filename=readdir ($open))
{
$filelist[]=$filename;
$size=$size+filesize($filename);
}
closedir ($open);
sort($filelist);
$count=count($filelist);
print("<table width=650 align=center cellspacing=0 cellpadding=2
border=1>");
print("<tr><td colspan=3 align=center><strong>Total number of files and
directories=$count occupying $size Kbytes</strong></td></tr>");
for($number=2;
$number<$count;
$number++)
{
$i++;
print("<tr><td align=right width=40>$i &nbsp; </td><td> &nbsp; &nbsp; <a
href=\"$filelist[$number]\">$filelist[$number]</a></td><td width=180
align=right><font color=\"#707070\">Go to </font><a href=\"#top of
page\">top of page</a>. &nbsp; </td></tr>");
}
print("</table>");
print("</td></tr></table>");
?>

Don't forget www.php.net

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация