php 递归删除目录(文件夹)
//删除单个空文件夹
代码如下 | 复制代码 |
$dir = 'www.111cn.net'; |
//下面来看一个批量递归删除目录的函数吧。
代码如下 | 复制代码 |
function deletedir($dir){ if(!handle=@opendir($dir)){ //检测要打开目录是否存在 die("没有该目录"); } while(false !==($file=readdir($handle))){ if($file!=="."&&$file!==".."){ //排除当前目录与父级目录 $file=$dir .directory_separator. $file; if(is_dir($file)){ deletedir($file); }else{ if(@unlink($file)){ echo "文件<b>$file</b>删除成功。<br>"; }else{ echo "文件<b>$file</b>删除失败!<br>"; } } } if(@rmdir($dir)){ echo "目录<b>$dir</b>删除成功了。<br> "; }else{ echo "目录<b>$dir</b>删除失败!<br> "; } } |
//测试程序
$dir="/var/www/test";
deletedir($dir);
并通过memcached协议与守护进程通信。但是它并不提供冗余(例如,复制其hashmap条目);当某个服务器s停止运行或崩溃了,所有存放在s上的键/值对都将丢失。 memcached由danga interactive开发,用于提升livejournal.com访问速度的。lj每秒动态页面访问量几千次,用户700万。memcached将数据库负载大幅度降低,更好的分配资源,更快速访问。
memcache常用方法
memcache::add — 添加一个值,如果已经存在,则返回false
memcache::addserver — 添加一个可供使用的服务器地址
memcache::close — 关闭一个memcache对象
memcache::connect — 创建一个memcache对象
memcache::debug — 控制调试功能
memcache::decrement — 对保存的某个key中的值进行减法操作
memcache::delete — 删除一个key值
memcache::flush — 清除所有缓存的数据
memcache::get — 获取一个key值
memcache::getextendedstats — 获取进程池中所有进程的运行系统统计
memcache::getserverstatus — 获取运行服务器的参数
memcache::getstats — 返回服务器的一些运行统计信息
memcache::getversion — 返回运行的memcache的版本信息
memcache::increment — 对保存的某个key中的值进行加法操作
memcache::pconnect — 创建一个memcache的持久连接对象
memcache::replace — r对一个已有的key进行覆写操作
memcache::set — 添加一个值,如果已经存在,则覆写
memcache::setcompressthreshold — 对大于某一大小的数据进行压缩
memcache::setserverparams — 在运行时修改服务器的参数
memcache方法使用
代码如下:
代码如下 | 复制代码 |
<?php教程 $memcache = new memcache; $memcache->connect('127.0.0.1', 11211) or die("连接失败"); $memcache->set('name', '张三'); $val = $memcache->get('name'); ?> |
注:set方法的完整版本,set(键名,键值,是否压缩,保持时间)
代码如下:
代码如下 | 复制代码 |
<?php $memcache = new memcache; $memcache -> connect('127.0.0.1', 11211) or die("连接失败"); $memcache -> set('name', array('一个','两个')); $val = $memcache->get('name'); print_r($val); $memcache -> close(); ?> |
require("lib_splitword_full.php");
$str = "一线楼市交易清淡";
$t1 = exectime();
$sp = new splitword();
$t2 = exectime();
//$t0 = $t2-$t1;
//echo "载入时间: $t0 <br><br>";
echo $sp->findnewword($sp->splitrmm($str))."<hr>";
echo $sp->splitrmm($str)."<hr>";
$sp->clear();
echo $str."<br>";
$t3 = exectime();
$t0 = $t3-$t2;
echo "<br>处理时间: $t0 <br><br>";
function exectime(){
$time = explode(" ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
代码如下 | 复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <body> <?php |
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate">
<title>ajax+php教程文件管理系统</title>
<style type="text/css教程">
@charset "utf-8";
/* css document */
<!--
body {
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
margin: 0px auto;
color: #777;
line-height: 18px;
padding-top: 0px;
font-family: tahoma, arial, helvetica, sans-serif;
background-color: #fff
}
*+html body {
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
margin: 0px auto;
color: #777;
line-height: 18px;
padding-top: 0px;
font-family: "微软雅黑", ahoma, arial, helvetica, sans-serif;
background-color: #fff
}
a {
text-decoration:none
}
input {
padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px
}
.main {
background-color:#bfe6bc;
margin:100px auto;
width:800px;
height:180px;
border:8px #399c26 solid;
}
.header {
text-align:center;
margin:10px auto;
width:100%;
display:block
}
.header h1 {
font-size:20px;
color:#399c26
}
.header p {
padding:0px;
margin-top:-10px;
}
.header p span{
font-size:12px;
color:#fff
}
.button_list {
margin:10px auto;
width:382px;
height:110px;
display:block
}
.button {
width:100px;
border:8px #399c26 solid;
height:20px;
line-height:20px;
font-size:14px;
float:left;
text-align:center;
margin-left:10px;
margin-bottom:10px;
background-color:#399c26
}
.button a{
color:#fff;
font-weight:bold
}
.footer {
text-align:center;
font-size:12px;
display:block;
margin:10px auto;
}
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}
.file_list {
display: none;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: 50%;
padding: 16px;
border: 8px solid #399c26;
background-color: white;
z-index:1002;
overflow: auto;
background-color:#bfe6bc;
}
.file_list_t {
margin:0 auto;
display:inline;
}
.file_list_t li {
font-size:14px;
list-style-type:none;
padding:0px;
background-color:#bfe6bc;
border-bottom:1px #ccc solid;
}
*+html .file_list_t li {
font-size:14px;
background:url(images/list_ico_1.gif) #fff no-repeat 7px 50%;
list-style-type:none;
text-indent:5px;
padding:0px;
background-color:#bfe6bc;
border-bottom:1px #ccc solid;
}
*+html .file_list_t li span {
float:right;
font-weight:bold;
margin-top:-20px;
}
.file_list_t li span {
float:right;
font-weight:bold;
margin-top:0px;
}
.file_list_t li a{
color:#399c26;
}
.file_list_close {
display: none;
position: absolute;
top: 22%;
left: 75%;
width: 30px;
height: 16px;
border: 1px solid #399c26;
z-index:1002;
background-color:#399c26;
color:#fff;
line-height:16px;
text-align:center
}
.file_list_close a{
color:#fff;
}/* file_content_input_form */
.file_content_input_form{
margin:0 auto;
width:450px;
padding:14px;
}
/* input_box */
#input_box{
}
#input_box h1 {
font-size:14px;
font-weight:bold;
margin-bottom:8px;
}
#input_box p{
font-size:11px;
color:#399c26;
margin-bottom:20px;
border-bottom:solid 1px #b7ddf2;
padding-bottom:10px;
}
#input_box label{
display:block;
font-weight:bold;
text-align:right;
width:140px;
float:left;
}
#input_box .small{
color:#399c26;
display:block;
font-size:11px;
font-weight:normal;
text-align:right;
width:140px;
}
#input_box input{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #399c26;
width:200px;
margin:2px 0 20px 10px;
}
#input_box textarea{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #399c26;
width:200px;
height:150px;
margin:2px 0 20px 10px;
}
#input_box button{
clear:both;
margin-left:150px;
width:125px;
height:31px;
background:#399c26;
text-align:center;
line-height:31px;
color:#ffffff;
font-size:11px;
font-weight:bold;
}
-->
</style>
<script type="text/网页特效" src="ajax.网页特效"></script>
</head>
<body>
<div class="main">
<div class="header">
<h1>欢迎使用anfms</h1>
<p><span>v0.1.0 alpha</span></p>
</div>
<div class="button_list">
<div class="button"><a href="网页特效:void(0);" onclick="javascript:file_list('/');document.getelementbyid('file_list').style.display='block';document.getelementbyid('file_list_close').style.display='block';document.getelementbyid('fade').style.display='block'">文件列表</a></div>
<div class="button"><a href="javascript:void(0);" onclick="javascript:file_list('/');document.getelementbyid('file_make').style.display='block';document.getelementbyid('file_list_close').style.display='block';document.getelementbyid('fade').style.display='block'">创建文件</a></div>
<div class="button"><a href="javascript:void(0);" onclick="document.getelementbyid('file_content_input').style.display='block';document.getelementbyid('file_list_close').style.display='block';document.getelementbyid('fade').style.display='block'">写入内容</a></div>
<div class="button"><a href="javascript:void(0);" onclick="document.getelementbyid('file_get_content').style.display='block';document.getelementbyid('file_list_close').style.display='block';document.getelementbyid('fade').style.display='block'">读取内容</a></div>
</div>
<div class="footer">
<p>
©2009-2010 uniter.com.cn powered by uniter team<br />
supported by ie7+ firefox opera
</p>
</div>
<div class="file_list_close" id="file_list_close">
<a href="javascript:void(0);" onclick="document.getelementbyid('file_list').style.display='none';document.getelementbyid('file_content_input').style.display='none';document.getelementbyid('file_get_content').style.display='none';document.getelementbyid('file_list_close').style.display='none';document.getelementbyid('fade').style.display='none';location.reload()">x</a>
</div>
<div class="file_list" id="file_list"></div>
<div class="file_list" id="file_content_input">
<div id="input_box" class="file_content_input_form">
<form id="form" name="form" method="post" action="">
<label>文件名
<span class="small">例如:abc.txt</span>
</label>
<input type="text" name="input_name" id="input_name" />
<label>内容值
<span class="small">添加文件内容</span>
</label>
<textarea name="input_content" id="input_content"></textarea>
<button type="button" onclick="javascript:file_content_input('input_name='+document.getelementbyid('input_name').value+'&input_content='+document.getelementbyid('input_content').value);">确定</button>
<div class="spacer"></div>
</form>
</div>
</div>
<div class="file_list" id="file_get_content">
<div id="input_box" class="file_content_input_form">
<form id="get_form" name="get_form" method="post" action="">
<label>文件名
<span class="small">例如:abc.txt</span>
</label>
<input type="text" name="input_name" id="input_name" />
<button type="button" onclick="javascript:file_get_content('input_name='+document.get_form.input_name.value);">确定</button>
<div class="spacer"></div>
</form>
</div>
</div>
<div class="file_list" id="file_make">
<div id="input_box" class="file_content_input_form">
<form id="make_form" name="make_form" method="post" action="">
<label>文件夹
<span class="small">例如:abc</span>
</label>
<input type="text" name="input_name" id="input_name" />
<button type="button" onclick="javascript:file_make('input_name='+document.make_form.input_name.value);">确定</button>
<div class="spacer"></div>
</form>
</div>
</div>
<div id="fade" class="black_overlay"></div>
</div>
</body>
</html>
ajax.网页特效
<script>
// javascript document
function do_ajax() {
}
function ajax_get_data(id) {
}
function file_list(path) {
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this www.111cn.net browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_list').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=filelist&path='+path);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
function file_content_input(data) {
var data;
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_content_input').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=inputcontent&'+data);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
function file_get_content(data) {
var data;
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_get_content').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=getcontent&'+data);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
function file_make(file) {
var file;
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_make').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=filemake&'+file);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
function file_delete(file) {
var file;
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_list').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=delete_file&file='+file);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
function dir_delete(file) {
var file;
var xhr;
if (window.xmlhttprequest) {
xhr = new xmlhttprequest();
}else if (window.activexobject) {
xhr = new activexobject("msxml2.xmlhttp");
}else {
throw new error("ajax is not supported by this browser");
}
xhr.onreadystatechange = function () {
if (xhr.readystate == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
document.getelementbyid('file_list').innerhtml = xhr.responsetext;
}
}
}
xhr.open('get','anfms.php?action=delete_dir&file='+file);
xhr.setrequestheader("if-modified-since","0");
xhr.send();
}
</script>
anfms.php
<?php
/**
* all needs file e 111cn.net manage system
* this is a test code
* return data to ajax
* by aiens
* 2010-01-13 19:20
*/header("content-type: text/html; charset=utf-8");
$document_root = $_server['document_root'];
if ($_get['action'] == 'filelist') { //return file list
echo '<div class="file_list_t">';
$checkpath = str_replace($document_root,'',$_get['path']);
if ($checkpath != '/../') {
$checkpath = str_replace('../','',$checkpath);
$path1 = $document_root.str_replace($document_root,'',$_get['path']);
$dir = opendir($path1);
while ($file = readdir($dir)) {
if (!($file == '..')) {
if ($file == '.') {
$path = $path1.'../';
$file = '返回';
if ($checkpath != '/') {
echo '<li><a href="javascript:void(0);" onclick="javascript:file_list(''.$path.'');">'.$file.'</a></li>';
}
}else{
$path = $path1.$file.'/';
$path = iconv('gb2312','utf-8',$path);
if (is_dir($path1.$file)) {
echo '<li><a href="javascript:void(0);" onclick="javascript:file_list(''.$path.'');">'.$file.'</a><span><a href="javascript:void(0);" onclick="javascript:if(confirm('确认删除?')) dir_delete(''.$path.'');">删除</a></span></li>';
}else{
$file = iconv('gb2312','utf-8',$file);
$filesize = filesize($path1.$file)/1000;
echo '<li>'.$file.' - ('.$filesize.'kb)<span><a href="javascript:void(0);" onclick="javascript:if(confirm('确认删除?')) file_delete(''.$path1.$file.'');">删除</a></span></li>';
}
}
}
}
closedir($dir);
}
echo '</div>';
}else if ($_get['action'] == 'inputcontent') { //input data to file
$name = $_get['input_name'];
$content = $_get['input_content'];
$data = date('y-m-d h:i:s');
$fp = @fopen(dirname(__file__).'/'.$name, 'ab');
$data = "data:".$data."t content:".$content."n";
$fw = @fwrite($fp, $data, strlen($data));
@fclose($fp);
if ($fw) {
echo '成功写入';
}else{
echo '写入失败';
}
}else if ($_get['action'] == 'getcontent') { //get data to file
$name = $_get['input_name'];
$fp = @fopen(dirname(__file__).'/'.$name, 'rb');
if (!$fp) {
echo 'www.111cn.net 系统所在目录不存在此文件,无法读取';
exit;
}
while (!feof($fp)) {
$content = fgets($fp);
echo $content.'<br />';
}
}else if ($_get['action'] == 'filemake') { //make dir
$name = $_get['input_name'];
function makedir($path) {
if (!file_exists($path)) {
makedir(dirname($path));
return mkdir($path, 0777);
}
}
if (makedir($name)) {
echo '成功创建';
}else{
echo '创建失败';
}
}else if ($_get['action'] == 'delete_file') { //delete file
$file = $_get['file'];
unlink($file);
echo '成功删除';
}else if ($_get['action'] == 'delete_dir') { //delete dir
$dir = $_get['file'];
function delete_dir($dir) {
if(! is_dir($dir)) {
return false;
}
$handle = @opendir($dir);
while(($file = @readdir($handle)) !== false) {
if($file != '.' && $file != '..') {
$dir = $dir . '/' . $file;
is_dir($dir) ? delete_dir($dir) : @unlink($dir);
}
}
closedir($handle);
return rmdir($dir) ;
}
if (delete_dir($dir)) {
echo '成功删除';
}else{
echo '删除失败';
}
}
?>
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
- php获取一个文件夹的mtime的程序了,这个就是时间问题了,对于这个问题我们来看小编整理的几个例子,具体的操作例子如下所示。 php很容易获取到一个文件夹的mtime,可以...2016-11-25
- 复制代码 代码如下: <td> <a href="/member/life/edit_ppt/<?php echo $v->id;?>" class="btn">编辑</a> <a href="javascript:;" onclick="if(confirm('您确定删除这条记录?')){location.href='/member/life/d...2014-06-07
- 伪造跨站请求介绍伪造跨站请求比较难以防范,而且危害巨大,攻击者可以通过这种方式恶作剧,发spam信息,删除数据等等。...2013-10-01
- 最近由于项目的需要,需要动态的添加和删除table中的tr,感觉用JS可以实现,但是在网上找了一下,单纯的自己写JS,感觉太麻烦,而且也不好维护。于是想到了最近学的jQuery。这篇文章给大家用实例介绍了jQuery动态添加与删除tr行的方法,有需要的朋友们可以参考借鉴。...2016-10-20
Centos中彻底删除Mysql(rpm、yum安装的情况)
我用的centos6,mysql让我整出了各种问题,我想重装一个全新的mysql,yum remove mysql-server mysql之后再install并不能得到一个干净的mysql,原来的/etc/my.cnf依然没变,datadir里面的数据已没有任何变化,手动删除/etc/my.cn...2015-03-15- 数据库中的数据删除会分为两种:物理删除 和 逻辑删除,接下来通过本文给大家介绍MyBatis-Plus的物理删除和逻辑删除使用场景分析,感兴趣的朋友一起看看吧...2021-09-25
- 这篇文章主要介绍了mybatis-plus getOne和逻辑删除,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-08-26
- 这篇文章主要为大家详细介绍了js实现上传文件添加和删除文件选择框 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-25
- 这篇文章主要介绍了C# 复制与删除文件的实现方法的相关资料,希望通过本文能帮助到大家,让大家理解掌握这部分内容,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#删除UL LI中指定标签里文字的方法,涉及C#针对页面HTML元素进行正则匹配与替换的相关操作技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了MybatisPlus实现逻辑删除功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-25
- 这篇文章主要介绍了C++递归删除一个目录的实现方法,涉及到目录的操作及递归算法的应用,需要的朋友可以参考下...2020-04-25
C#使用FolderBrowserDialog类实现选择打开文件夹方法详解
这篇文章主要介绍了C#选择文件夹/打开文件夹/浏览文件夹等代码方法,大家参考使用...2020-06-25JQuery EasyUI学习教程之datagrid 添加、修改、删除操作
这篇文章主要介绍了JQuery EasyUI datagrid 添加、修改、删除操作的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下...2016-07-25- 这篇文章主要介绍了jQuery中DOM节点的删除方法,文中介绍的很相信,内容包括empty()的基本用法、remove()的有参用法和无参用法、empty和remove区别、保留数据的删除操作detach()以及detach()和remove()区别,需要的朋友可以参考借鉴。...2017-01-26
- 这篇文章主要介绍了解决IDEA target文件夹越来越大的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-22
- 本文实例讲述了MySQL查看、创建和删除索引的方法。分享给大家供大家参考。具体如下:1.索引作用在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率。特别是当数据量非常大,查询...2015-10-21
- 这篇文章主要介绍了微信小程序 向左滑动删除功能的实现的相关资料,需要的朋友可以参考下...2017-03-13
- 在本篇文章里小编给大家分享了关于C#删除Excel中的图片的实例代码内容,有兴趣的朋友们参考学习下。...2020-06-25