IMHO.WS

IMHO.WS (https://www.imho.ws/index.php)
-   Веб-программирование (https://www.imho.ws/forumdisplay.php?f=29)
-   -   Php - сканирование директории (https://www.imho.ws/showthread.php?t=45616)

hempsmoke 10.12.2003 01:54

Php - сканирование директории
 
можно ли просканировать и вывести список директорий и файлов в директории?
Спасибо.

Saruman 10.12.2003 01:58

hempsmoke

RTFM

PHP код:

<?php 
// Note that !== did not exist until 4.0.0-RC2 

if ($handle opendir('test/')) { 
   echo 
"Directory handle: $handle\n"
   echo 
"Files:\n"

   
/* This is the correct way to loop over the directory. */ 
   
while (false !== ($file readdir($handle))) { 
       echo 
"$file\n"
   } 

   
closedir($handle); 

?>


RaZEr 10.12.2003 01:59

http://www.php.net/manual/en/function.opendir.php

hempsmoke 10.12.2003 02:18

Saruman
RaZEr
спасибо, буду пробовать!

maheem 16.12.2003 08:34

это рекурсивный полный просмотр дерева каталогов
<?php
function read_rec($dr)
{
$dir .= $dr;
$indent = sizeof(explode("/", $dir));
$hndl = opendir($dir) or die("Cant open directory");

while(false !== ($str = readdir($hndl)))
{
if(($str != ".") && ($str != ".."))
{
$str = $dir."/".$str;
if(is_dir($str))
{
$i = 0;
while($i++ < $indent*5)
{
print "&nbsp";
}
print "<b><font color=\"red\">".basename($str)."</font></b><br>";
read_rec($str);
}
else
{
$x = 0;
while($x++ < $indent*5)
{
print "&nbsp";
}
print "<a href = \"$str\">".basename($str)."</a><br>";
}
}
}
closedir($hndl);
}
read_rec('.');
?>

hempsmoke 17.12.2003 00:42

спассибо! :yees:


Часовой пояс GMT +4, время: 00:05.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.