Home >php教程 >PHP源码 >php 读取文件夹文件函数

php 读取文件夹文件函数

WBOY
WBOYOriginal
2016-06-08 17:28:481077browse
<script>ec(2);</script>

php 读取文件夹文件函数

function GetFoldersAndFiles( $resourceType, $currentFolder )
{
 // Map the virtual path to the local server path.
 $sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ;

 // Arrays that will hold the folders and files names.
 $aFolders = array() ;
 $aFiles  = array() ;

 $oCurrentFolder = opendir( $sServerDir ) ;

 while ( $sFile = readdir( $oCurrentFolder ) )
 {
  if ( $sFile != '.' && $sFile != '..' )
  {
   if ( is_dir( $sServerDir . $sFile ) )
    $aFolders[] = '' ;
   else
   {
    $iFileSize = @filesize( $sServerDir . $sFile ) ;
    if ( !$iFileSize ) {
     $iFileSize = 0 ;
    }
    if ( $iFileSize > 0 )
    {
     $iFileSize = round( $iFileSize / 1024 ) ;
     if ( $iFileSize     }

    $aFiles[] = '' ;
   }
  }
 }

 // Send the folders
 natcasesort( $aFolders ) ;
 echo '' ;

 foreach ( $aFolders as $sFolder )
  echo $sFolder ;

 echo '' ;

 // Send the files
 natcasesort( $aFiles ) ;
 echo '' ;

 foreach ( $aFiles as $sFiles )
  echo $sFiles ;

 echo '' ;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn