PHP剔除文件

Jun 13, 2016 am 11:00 AM
dir dirname file

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

?

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

Hongmeng native application random poetry

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use java's File.length() function to get the size of the file

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Rename files using java's File.renameTo() function

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of the file

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of the file

How to delete a file or directory using File.delete() method in Java? How to delete a file or directory using File.delete() method in Java? Nov 18, 2023 am 08:02 AM

How to delete a file or directory using File.delete() method in Java?

WebView File Domain Origin Policy Bypass Vulnerability Example Analysis WebView File Domain Origin Policy Bypass Vulnerability Example Analysis May 15, 2023 am 08:22 AM

WebView File Domain Origin Policy Bypass Vulnerability Example Analysis

See all articles