php文件以及文件夹操作
function get_dir($dir){
$file = @ scandir($dir);
foreach($file as $key){
if ( $key != ".." && $key != "." ){
$files[] = $key;
}
}
return $files;
}
function dir_list($path, $exts = '', $list= array()) {
$path = dir_path($path);
$files = glob($path.'*');
foreach($files as $v) {
$fileext = fileext($v);
if (!$exts || preg_match("/\.($exts)/i", $v)) {
$list[] = $v;
if (is_dir($v)) {
$list = dir_list($v, $exts, $list);
}
}
}
return $list;
}
function dir_path($path) {
$path = str_replace('\\', '/', $path);
if(substr($path, -1) != '/') $path = $path.'/';
return $path;
}
function fileext($filename) {
return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
}
function dir_delete($dir) {
$dir = dir_path($dir);
if (!is_dir($dir)) return FALSE;
$list = glob($dir.'*');
foreach($list as $v) {
is_dir($v) ? dir_delete($v) : @unlink($v);
}
return @rmdir($dir);
}