Edit File by line
/home/barbar84/public_h.../extracte.../dirfunc
File: dir.func.php
<?php
[0] Fix | Delete
//打开指定目录
[1] Fix | Delete
/**
[2] Fix | Delete
* 遍历目录函数,只读取目录中的最外层的内容
[3] Fix | Delete
* @param string $path
[4] Fix | Delete
* @return array
[5] Fix | Delete
*/
[6] Fix | Delete
function readDirectory($path) {
[7] Fix | Delete
$handle = opendir ( $path );
[8] Fix | Delete
while ( ($item = readdir ( $handle )) !== false ) {
[9] Fix | Delete
//.和..这2个特殊目录
[10] Fix | Delete
if ($item != "." && $item != "..") {
[11] Fix | Delete
if (is_file ( $path . "/" . $item )) {
[12] Fix | Delete
$arr ['file'] [] = $item;
[13] Fix | Delete
}
[14] Fix | Delete
if (is_dir ( $path . "/" . $item )) {
[15] Fix | Delete
$arr ['dir'] [] = $item;
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
}
[19] Fix | Delete
}
[20] Fix | Delete
closedir ( $handle );
[21] Fix | Delete
return $arr;
[22] Fix | Delete
}
[23] Fix | Delete
//$path="file";
[24] Fix | Delete
//print_r(readDirectory($path));
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* 得到文件夹大小
[28] Fix | Delete
* @param string $path
[29] Fix | Delete
* @return int
[30] Fix | Delete
*/
[31] Fix | Delete
function dirSize($path){
[32] Fix | Delete
$sum=0;
[33] Fix | Delete
global $sum;
[34] Fix | Delete
$handle=opendir($path);
[35] Fix | Delete
while(($item=readdir($handle))!==false){
[36] Fix | Delete
if($item!="."&&$item!=".."){
[37] Fix | Delete
if(is_file($path."/".$item)){
[38] Fix | Delete
$sum+=filesize($path."/".$item);
[39] Fix | Delete
}
[40] Fix | Delete
if(is_dir($path."/".$item)){
[41] Fix | Delete
$func=__FUNCTION__;
[42] Fix | Delete
$func($path."/".$item);
[43] Fix | Delete
}
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
}
[47] Fix | Delete
closedir($handle);
[48] Fix | Delete
return $sum;
[49] Fix | Delete
}
[50] Fix | Delete
//$path="file";
[51] Fix | Delete
//echo dirSize($path);
[52] Fix | Delete
[53] Fix | Delete
function createFolder($dirname){
[54] Fix | Delete
//检测文件夹名称的合法性
[55] Fix | Delete
if(checkFilename(basename($dirname))){
[56] Fix | Delete
//当前目录下是否存在同名文件夹名称
[57] Fix | Delete
if(!file_exists($dirname)){
[58] Fix | Delete
if(mkdir($dirname,0777,true)){
[59] Fix | Delete
$mes="文件夹创建成功";
[60] Fix | Delete
}else{
[61] Fix | Delete
$mes="文件夹创建失败";
[62] Fix | Delete
}
[63] Fix | Delete
}else{
[64] Fix | Delete
$mes="存在相同文件夹名称";
[65] Fix | Delete
}
[66] Fix | Delete
}else{
[67] Fix | Delete
$mes="非法文件夹名称";
[68] Fix | Delete
}
[69] Fix | Delete
return $mes;
[70] Fix | Delete
}
[71] Fix | Delete
/**
[72] Fix | Delete
* 重命名文件夹
[73] Fix | Delete
* @param string $oldname
[74] Fix | Delete
* @param string $newname
[75] Fix | Delete
* @return string
[76] Fix | Delete
*/
[77] Fix | Delete
function renameFolder($oldname,$newname){
[78] Fix | Delete
//检测文件夹名称的合法性
[79] Fix | Delete
if(checkFilename(basename($newname))){
[80] Fix | Delete
//检测当前目录下是否存在同名文件夹名称
[81] Fix | Delete
if(!file_exists($newname)){
[82] Fix | Delete
if(rename($oldname,$newname)){
[83] Fix | Delete
$mes="重命名成功";
[84] Fix | Delete
}else{
[85] Fix | Delete
$mes="重命名失败";
[86] Fix | Delete
}
[87] Fix | Delete
}else{
[88] Fix | Delete
$mes="存在同名文件夹";
[89] Fix | Delete
}
[90] Fix | Delete
}else{
[91] Fix | Delete
$mes="非法文件夹名称";
[92] Fix | Delete
}
[93] Fix | Delete
return $mes;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
function copyFolder($src,$dst){
[97] Fix | Delete
//echo $src,"---",$dst."----";
[98] Fix | Delete
if(!file_exists($dst)){
[99] Fix | Delete
mkdir($dst,0777,true);
[100] Fix | Delete
}
[101] Fix | Delete
$handle=opendir($src);
[102] Fix | Delete
while(($item=readdir($handle))!==false){
[103] Fix | Delete
if($item!="."&&$item!=".."){
[104] Fix | Delete
if(is_file($src."/".$item)){
[105] Fix | Delete
copy($src."/".$item,$dst."/".$item);
[106] Fix | Delete
}
[107] Fix | Delete
if(is_dir($src."/".$item)){
[108] Fix | Delete
$func=__FUNCTION__;
[109] Fix | Delete
$func($src."/".$item,$dst."/".$item);
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
closedir($handle);
[114] Fix | Delete
return "复制成功";
[115] Fix | Delete
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* 剪切文件夹
[120] Fix | Delete
* @param string $src
[121] Fix | Delete
* @param string $dst
[122] Fix | Delete
* @return string
[123] Fix | Delete
*/
[124] Fix | Delete
function cutFolder($src,$dst){
[125] Fix | Delete
//echo $src,"--",$dst;
[126] Fix | Delete
if(file_exists($dst)){
[127] Fix | Delete
if(is_dir($dst)){
[128] Fix | Delete
if(!file_exists($dst."/".basename($src))){
[129] Fix | Delete
if(rename($src,$dst."/".basename($src))){
[130] Fix | Delete
$mes="剪切成功";
[131] Fix | Delete
}else{
[132] Fix | Delete
$mes="剪切失败";
[133] Fix | Delete
}
[134] Fix | Delete
}else{
[135] Fix | Delete
$mes="存在同名文件夹";
[136] Fix | Delete
}
[137] Fix | Delete
}else{
[138] Fix | Delete
$mes="不是一个文件夹";
[139] Fix | Delete
}
[140] Fix | Delete
}else{
[141] Fix | Delete
$mes="目标文件夹不存在";
[142] Fix | Delete
}
[143] Fix | Delete
return $mes;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* 删除文件夹
[148] Fix | Delete
* @param string $path
[149] Fix | Delete
* @return string
[150] Fix | Delete
*/
[151] Fix | Delete
function delFolder($path){
[152] Fix | Delete
$handle=opendir($path);
[153] Fix | Delete
while(($item=readdir($handle))!==false){
[154] Fix | Delete
if($item!="."&&$item!=".."){
[155] Fix | Delete
if(is_file($path."/".$item)){
[156] Fix | Delete
unlink($path."/".$item);
[157] Fix | Delete
}
[158] Fix | Delete
if(is_dir($path."/".$item)){
[159] Fix | Delete
$func=__FUNCTION__;
[160] Fix | Delete
$func($path."/".$item);
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
closedir($handle);
[165] Fix | Delete
rmdir($path);
[166] Fix | Delete
return "文件夹删除成功";
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
[170] Fix | Delete
[171] Fix | Delete
[172] Fix | Delete
[173] Fix | Delete
[174] Fix | Delete
[175] Fix | Delete
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
[179] Fix | Delete
[180] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function