PHP剔除文件

WBOY
Release: 2016-06-13 13:04:43
Original
812 people have browsed it

PHP删除文件

???? 这是一个很不错的PHP删除文件类,很实用,跟大家分享,我过去PHP菜的时候找这个就找了好久呢,呵呵

?

<?php
//创建删除文件类
class DELFILE
{
function removeDir($dirName) 
{ 

    if(! is_dir($dirName))  //判断指定目录是存在
    { 
        @unlink($dirName);
        return false; 
    } 
	
    $handle = @opendir($dirName);  //打开目录
	
    while(($file = @readdir($handle)) !== false) 
    { 
        
        if($file != '.' && $file != '..')  //列出目录中的所有文件并去掉 . 和 ..
        { 
            $dir = $dirName . '/' . $file; 
            is_dir($dir) ? removeDir($dir) : @unlink($dir);   //删除指定目录中的文件
        } 
    } 
    closedir($handle);   //关闭由opendir()打开的目录
     
    return rmdir($dirName) ;  //rmdir()删除空目录 
} 

}
$ob_del=new DELFILE();    //实例化类

$dirName="G:/123/123.jpg";     //这里是指定的路径
$ob_del->removeDir($dirName);  //执行方法

/*----------------------------------------------*/
/*------------------结束------------------------*/
/*-----------------------------------------------*/
?>
Copy after login

?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template