/**
* 文件夹大小
* @param $path
* @return int
*/
function dirsize($path)
{
/* 初始条件 */
$size = 0;
$stack = array();
if (file_exists($path)) {
$path = realpath($path) . '/';
array_push($stack, '');
} else {
return -1;
}
/* 迭代条件 */
while (count($stack) !== 0) {
$dir = array_pop($stack);
$handle = opendir($path . $dir);
/* 执行过程 */
while (($item = readdir($handle)) !== false) {
if ($item == '.' || $item == '..') continue;
$_path = $path . $dir . $item;
if (is_file($_path)) $size += filesize($_path);
/* 更新条件 */
if (is_dir($_path)) array_push($stack, $dir . $item . '/');
}
closedir($handle);
}
return $size;
}
/**
* 复制文件夹
* @param $source
* @param $dest
* @return string
*/
function copydir($source, $dest)
{
/* 初始条件 */
$stack = array();
$target = '';
if (file_exists($source)) {
if (!file_exists($dest)) mkdir($dest);
$source = realpath($source) . '/';
$dest = realpath($dest) . '/';
$target = realpath($dest);
array_push($stack, '');
}
/* 迭代条件 */
while (count($stack) !== 0) {
$dir = array_pop($stack);
$handle = opendir($source . $dir);
if (!file_exists($dest . $dir)) mkdir($dest . $dir);
/* 执行过程 */
while (($item = readdir($handle)) !== false) {
if ($item == '.' || $item == '..') continue;
$_source = $source . $dir . $item;
$_dest = $dest . $dir . $item;
if (is_file($_source)) copy($_source, $_dest);
/* 更新条件 */
if (is_dir($_source)) array_push($stack, $dir . $item . '/');
}
closedir($handle);
}
return $target;
}
/**
* 删除文件夹
* @param $path
* @return bool
*/
function rmdirs($path)
{
/* 初始化条件 */
$stack = array();
if (!file_exists($path)) return false;
$path = realpath($path) . '/';
array_push($stack, '');
/* 迭代条件 */
while (count($stack) !== 0) {
$dir = end($stack);
$items = scandir($path . $dir);
/* 执行过程 */
if (count($items) === 2) {
rmdir($path . $dir);
array_pop($stack);
continue;
}
/* 执行过程 */
foreach ($items as $item) {
if ($item == '.' || $item == '..') continue;
$_path = $path . $dir . $item;
if (is_file($_path)) unlink($_path);
/* 更新条件 */
if (is_dir($_path)) array_push($stack, $dir . $item . '/');
}
}
return !(file_exists($path));
}
/**
* 函数执行毫秒数
* @param $func
* @return int
*/
function exec_time($func)
{
$start = explode(' ', microtime());
$func();// 执行耗时操作
$end = explode(' ', microtime());
$sec_time = floatval($end[0]) - floatval($start[0]);
$mic_time = floatval($end[1]) - floatval($start[1]);
return intval(($sec_time + $mic_time) * 1000);
}
echo exec_time(function () {
/* 执行的耗时操作 */
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有