/ Published in: PHP
Very simple to use.
**Calling:**
$files = dirContents(DIR_PATH, [FILTER, [TYPE]]);
**Examples:**
$files = dirContens("my-dir");
_$files_ is array containing all, both files either directories
$files = dirContens("my-dir", "img[0-9]");
_$files_ is array containing files or directories with 'img0', 'img1', 'img2', etc. in their names
$files = dirContents("my-dir/", "\.php", 1);
_$files_ is array containing only files with '.php' in their names
**Tip:**
After calling _dirContents()_ try to call *print_r* for showing the array of files
echo '<pre>';
print_r($files);
echo '</pre>';
Thank you for your comments.
**Calling:**
$files = dirContents(DIR_PATH, [FILTER, [TYPE]]);
**Examples:**
$files = dirContens("my-dir");
_$files_ is array containing all, both files either directories
$files = dirContens("my-dir", "img[0-9]");
_$files_ is array containing files or directories with 'img0', 'img1', 'img2', etc. in their names
$files = dirContents("my-dir/", "\.php", 1);
_$files_ is array containing only files with '.php' in their names
**Tip:**
After calling _dirContents()_ try to call *print_r* for showing the array of files
echo '<pre>';
print_r($files);
echo '</pre>';
Thank you for your comments.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Reading directory contents * @param STRING $dir - Name of the directory * @param STRING $filter - Regular expression * @param BOOLEAN $type - 0 => Files and directories, 1 => Only files, 2 => Only directories * @return ARRAY|BOOLEAN - Returning array if success, else FALSE */ function dirContents($dir, $filter=null, $type=0) { $dir .= "/"; { { if($file!="." && $file!="..") { $arrayOfFiles[] = $file; } } return($arrayOfFiles); }else{return false;} }