2052 Posts in 477 Topics- by 811 Members - Latest Member: canmasagi

Pages: [1]   Go Down
  Print  
Author Topic: [PHP Code] Scanning All Files and Directories  (Read 432 times)
webmaster
Administrator
phpBB Guru
*****
Offline Offline

Posts: 914


hairulazami
View Profile WWW
« on: October 31, 2008, 09:36:01 AM »

Code:
<?php
function scanDirectories($rootDir) {
    
// set filenames invisible if you want
    
$invisibleFileNames = array("&#46;""&#46;&#46;""&#46;htaccess""&#46;htpasswd""thumbs&#46;db");
    
// run through content of root directory
    
$dirContent scandir($rootDir);
    
$allData = array();
    
// file counter gets incremented for a better
    
$fileCounter 0;
    foreach(
$dirContent as $key => $content) {
        
// filter all files not accessible
        
$path $rootDir&#46;'/'&#46;$content;
        
if(!in_array($content$invisibleFileNames)) {
            
// if content is file & readable, add to array
            
if(is_file($path) && is_readable($path)) {
                
$tmpPathArray explode("/",$path);
                
// saving filename
                
$allData[$fileCounter&#93;['fileName'&#93; = end($tmpPathArray);
                // saving while path (for better access)
                
$allData[$fileCounter&#93;['filePath'&#93; = $path;
                // get file extension
                
$filePartsTmp explode("&#46;"end($tmpPathArray));
                
$allData[$fileCounter&#93;['fileExt'&#93; = end($filePartsTmp);
                // get file date
                
$allData[$fileCounter&#93;['fileDate'&#93; = date('Y-m-d H&#58;i&#58;s', filectime($path));
                // get filesize in byte
                
$allData[$fileCounter&#93;['fileSize'&#93; = filesize($path);
                
$fileCounter++;
            
// if content is a directory and readable, add path and name
            
}elseif(is_dir($path) && is_readable($path)) {
                
$dirNameArray explode('/',$path);
                
$allData[$path&#93;['dirPath'&#93; = $path;
                
$allData[$path&#93;['dirName'&#93; = end($dirNameArray);
                // recursive callback to open new directory
                
$allData[$path&#93;['content'&#93; = scanDirectories($path);
            
}
        }
    }

    return 
$allData;
}

print_r(scanDirectories("D&#58;\dreserv\www\dredsync\dds-includes\images"));
?>
Logged


Pages: [1]   Go Up
  Print  
 
Jump to: