Home Backend Development PHP Tutorial thinkphp清空全部目录(包括子目录)

thinkphp清空全部目录(包括子目录)

Jun 13, 2016 am 10:54 AM
amp file gt lt return

thinkphp清空所有目录(包括子目录)

在admin项目的Common目录下common.php文件:/***   删除xml目录下的所有xml文件*   string $fp  文件路径(不包括文件名)*   string $fn  文件名称(包括扩展名)*   boolean $type 是否关联到所有子目录*/function delXML($type=true,$fn='',$fp='./xml'){ if(!is_dir($fp)){  return 'nodir';  //被删除目录不存在 }else{  if(!is_empty_dir($fp)){//如果不是空的        $H = @ opendir($fp);   while(false !== ($_file=readdir($H))){    //检索目录    if(is_dir($fp."/".$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){     if($type){      if(!is_empty_dir($fp.'/'.$_file)){//如果不是,调用自身,不过是原来的路径+他下级的目录名          delXML($type,$fn,$fp."/".$_file);      }         if(is_empty_dir($fp.'/'.$_file)){//如果是空就直接删除          rmdir($fp.'/'.$_file);         }        }    //检索文件    }else if(is_file($fp."/".$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){     if(eregi('/'.$file,'/'.$_file)){      if(!unlink($fp.'/'.$_file)){       return false; //删除失败      }     }    }   }   closedir($H);    }     return true;   //删除失败 }}   //判断目录是否为空,true为空,false为不空function is_empty_dir($fp)   {    $H = @ opendir($fp); $i=0;    while($_file=readdir($H)){     $i++;    }    closedir($H);    if($i>2){  return false; }else{  return true;   }} 调用方法:在admin项目的Action目录下SiteMapAction.class.php文件:class SiteMapAction extends Action { //删除全部xml目录地图文件 function delXML(){  $flag = delXML();  exit($flag); }} 静态页面ajax方法:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="../Public/js/jquery-1.4.2.min.js"></script><script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/artDialog/artDialog.min.js"></script><title>删除目录文件</title></head><body><script language="javascript">function delXML(){ if(!window.confirm('确定要删除整站地图吗?')){  return;  } var testDialog; testDialog = art.dialog({  lock: false,  title:'',  id:'loaddialog',  content:'<font color="#ff0000">正在删除中...</font>',  width:220 }); var url="{:U('delXML')}"; $.get(url,null,function(data){  //$("#con").append(data);  testDialog.close();  if(data == true){   alert('删除成功!');  }else if(data == false){   alert('删除失败,请稍候再试...');  }else if(data == 'nodir'){   alert('错误:被删除目录不存在');   } });}</script><input name="delete" type="button" class="agin agn"  value="全删除" onClick="javascript:return delXML();"/></body></html>
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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

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

Hongmeng native application random poetry

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

Detailed explanation of the usage of return in C language

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

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

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

See all articles