php递归遍历删除文件的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php递归遍历删除文件的方法。分享给大家供大家参考。具体如下:

这个函数稍加修改就可以变成一个递归文件拷贝函数

<?php
function mover($src,$dst) {
$handle=opendir($src);
// Opens source dir.
if (!is_dir($dst)) mkdir($dst,0755);
// Make dest dir.
while ($file = readdir($handle)) {
  if (($file!=".") and ($file!="..")) {
  // Skips . and .. dirs
    $srcm=$src."/".$file;
    $dstm=$dst."/".$file;
    if (is_dir($srcm)) {
    // If another dir is found
     mover($srcm,$dstm);
  // calls itself - recursive WTG
    } else {
     copy($srcm,$dstm);
     unlink($srcm);
  // Is just a copy procedure is needed
    } // comment out this line
  }
}
closedir($handle);
rmdir($src);
}
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP基于swoole多进程操作示例

PHP基于swoole多进程操作示例

本文实例讲述了PHP基于swoole多进程操作。分享给大家供大家参考,具体如下: 多个任务同时执行 将顺序执行的任务,转化为并行执行(任务在逻辑上可以并行执行) 比如,我们要对已知的用户...

将CMYK颜色值和RGB颜色相互转换的PHP代码

function hex2rgb($hex) { $color = str_replace('#','',$hex); $rgb = array('r' => hexdec(s...

php实现等比例压缩图片

本文实例为大家分享了php实现等比例压缩图片的具体代码,供大家参考,具体内容如下 /** * desription 压缩图片 * @param sting $imgsrc...

Warning: session_destroy() : Trying to destroy uninitialized sessionq错误

经查证,在进行使用session_destroy()函数必须先调用session_start()函数。 也就是要有如下代码: 复制代码 代码如下: <? session_start...

php flush无效,IIS7下php实时输出的方法

在一个比较费时的操作中,想把操作记录在浏览器上实时显示出来,用到了flush(),把缓冲中的内容发送到浏览器。但在iis7里面用fastcgi模式配置的php怎么都实现不了,结果总是一起...