插件24:目录列表

<?php // Plug-in 24: Directory List

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$directory = "c:\windows\\";
$result    = PIPHP_DirectoryList($directory);
echo         "<b>Listing:</b> $directory<br /><br />";

if ($result[0] == 0) echo "No Directories";
else
{
   echo "<b>Directories:</b> ";
   for ($j=0 ; $j < $result[0] ; ++$j)
      echo $result[2][$j] . ", ";
}

echo "<br /><br />";

if ($result[1] == 0) echo "No files";
else
{
   echo "<b>Files:</b> ";
   for ($j=0 ; $j < $result[1] ; ++$j)
      echo $result[3][$j] . ", ";
}

function PIPHP_DirectoryList($path)
{
   // Plug-in 24: Directory List
   //
   // This plug-in accepts a path to a directory on the hard
   // disk and returns the list of files located there. The
   // function returns an array with the first element set
   // to the number of subdirectories in the directory and the
   // second to the number of files. If none are found then
   // 0 is returned. The third and fourth elements returned
   // contain arrays with all the directories and file names
   // respectively. The argument required is:
   //
   //    $path: The directory to list

   $files = array();
   $dirs  = array();
   $fnum  = $dnum = 0;

   if (is_dir($path))
   {
      $dh = opendir($path);

      do
      {
         $item = readdir($dh);

         if ($item !== FALSE && $item != "." && $item != "..")
         {
            if (is_dir("$path/$item")) $dirs[$dnum++] = $item;
            else $files[$fnum++] = $item;
         }
      } while($item !== FALSE);
   
      closedir($dh);
   }

   return array($dnum, $fnum, $dirs, $files);
}

?>

插件说明:

本插件接受服务器某个目录的位置,以数组的形式返回这个目录的全部文件。如果操作成功,则返回一个四元素的数组。其中第一个元素是找到的目录个数;第二个元素是找到的文件个数;第三个元素是一个数组,用于保存找到的目录名;第四个元素也是一个数组,用于保存找到的全部文件名。如果操作失败则返回一个只有一个元素的数组,元素的值为FALSE。

他需要参数:$path:服务器某个目录的路径。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值