forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.class.php
More file actions
115 lines (112 loc) · 3.14 KB
/
Action.class.php
File metadata and controls
115 lines (112 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* 共通ファイル操作クラス(Action)
*
* @package NetCommons.component
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class File_Action {
var $_className = "File_Action";
/**
* ディレクトリ再帰削除関数
*
* @param string $path 対象パス
* @return bool true:正常,false:異常
**/
function delDir($path) {
// ファイルまたはディレクトリの削除
if ( is_dir($path) ) {
$handle = opendir($path);
while ( false !== ($file = readdir($handle)) ) {
if ( $file == '.' || $file == '..' ) { continue; }
$this->delDir($path. "/". $file);
}
closedir($handle);
return @rmdir($path);
} else {
@chmod($path, 0777);
return @unlink($path);
}
}
/**
* ディレクトリ再帰コピー関数
*
* @param string $path 対象パス
* @poaram string $copy_path コピー先パス
* @return bool true:正常,false:異常
**/
function copyDir($path, $copy_path) {
if(!is_dir( $path )) {
return false;
}
$oldmask = umask(0);
//$mod= stat($path);
//mkdir($copy_path, $mod[2]);
if(!@file_exists($copy_path)) {
$mk_result = mkdir($copy_path, 0777);
if(!$mk_result) {
return false;
}
}
$fileArray=glob( $path."*" );
if(is_array($fileArray)) {
foreach( $fileArray as $key => $value){
preg_match("/^(.*[\/])(.*)/",$value, $matches);
//mb_ereg("^(.*[\/])(.*)",$value, $matches);
$data=$matches[2];
if(is_dir($value)){
$this->copyDir( $value.'/', $copy_path."/".$data.'/' );
} else {
if(!copy( $value, $copy_path."/".$data )) return false;
//$mod=stat($data_ );
//chmod( $copy_path."/".$data, $mod[2] );
chmod($copy_path."/".$data, 0777);
}
}
}
umask($oldmask);
return true;
}
/**
* ファイルコピー関数
* $path_fileのファイルを$prefix_copy_path . $copy_path_fileにコピーする
* $copy_path_file内のパスでディレクトリがないものは作成する
*
* @param string $path_file
* @param string $copy_path_file
* @param string $prefix_path
*
*
* @return bool true:正常,false:異常
**/
function copyFile($path_file, $copy_path_file, $prefix_copy_path = "")
{
if(!file_exists($path_file)) {
// コピー元がなくてもエラーとしない
return true;
}
$copy_path_file_list = explode("/", $copy_path_file);
$copy_path_len = count($copy_path_file_list);
if($copy_path_len > 1) {
$full_path = $prefix_copy_path;
$count = 0;
foreach($copy_path_file_list as $path) {
$full_path .= $path . "/";
$count++;
if($full_path != '/' && !is_dir($full_path)) {
@mkdir($full_path, 0777);
}
if($count == $copy_path_len - 1) {
break;
}
}
if(!copy($path_file, $prefix_copy_path.$copy_path_file)) return false;
}
return true;
}
}
?>