<?php
/**
* Created by PhpStorm.
* User: ver
* Date: 16-3-4
* Time: 10:46
*/
class RmoveDir{ public $error = true; public function __construct(){ } /** * , */ public function rm_dir($path){ // if(!file_exists($path)) { $this->set_error( $path.' ' ); return false; } // : , ; , if ( is_dir($path) ){ $handle = opendir($path); while (($file = readdir($handle)) !== false){ // :. ,.. if( $file != '.' && $file != '..' ){ // $this->rm_dir( $path.DS.$file ); } } closedir($handle); rmdir($path); }else{ unlink($path); } return true; } /** * , aaa\bbb\ccc\... */ public function mk_dir($path, $mode = 0777) { $dirs = explode(DS,$path); $dir = ''; // , for ($i=0, $n=count($dirs); $i<$n; $i++) { $dir .= $dirs[$i].DS; if (!file_exists($dir)) mkdir($dir,$mode); } } /** * */ public function copy_dir($src, $dst, $overwrite = false) { if(!is_dir($dst)) $this->mk_dir($dst); $handle = opendir($src); if($handle) { while(false !== ($file = readdir($handle))) { if($file != '.' && $file != '..') { $path = $src.DS.$file; if(is_file($path)) { if(!is_file($dst.DS.$file) || $overwrite) @copy($path, $dst.DS.$file); } else { if(!is_dir($dst.DS. $file)) mkdir($dst.DS.$file); $this->copy_dir($path, $dst.DS.$file, $overwrite); } } } } closedir($handle); } public function set_error( $error ){ $this->error = $error; } public function get_error(){ return $this->error; } }