这篇文章主要介绍了php目录操作实例代码,需要的朋友可以参考下
复制代码 代码如下:
/**
* listdir
*/
header("content-type:text/html;charset=utf-8");
$dirname = "./final/factapplication";
function listdir($dirname) {
$ds = opendir($dirname);
while (false !== ($file = readdir($ds))) {
$path = $dirname.'/'.$file;
if ($file != '.' && $file != '..') {
if (is_dir($path)) {
listdir($path);
} else {
echo $file."
";
}
}
}
closedir($ds);
}
listdir($dirname);
核心:递归的经典应用,以及文件和目录的基本操作。
复制代码 代码如下:
/**
* copydir
*/
$srcdir = "../fileupload";
$dstdir = "b";
function copydir($srcdir, $dstdir) {
mkdir($dstdir);
$ds = opendir($srcdir);
while (false !== ($file = readdir($ds))) {
$path = $srcdir."/".$file;
$dstpath = $dstdir."/".$file;
if ($file != "." && $file != "..") {
if (is_dir($path)) {
copydir($path, $dstpath);
} else {
copy($path, $dstpath);
}
}
}
closedir($ds);
}
copydir($srcdir, $dstdir);
方科网络ERP图文店II版为仿代码站独立研发的网络版ERP销售程序。本本版本为方科网络ERP图文店版的简化版,去除了部分不同用的功能,使得系统更加精炼实用。考虑到图文店的特殊情况,本系统并未制作出入库功能,而是将销售作为重头,使用本系统,可以有效解决大型图文店员工多,换班数量多,订单混杂不清的情况。下单、取件、结算分别记录操作人员,真正做到订单全程跟踪!无限用户级别,不同的用户级别可以设置不同的价
0
核心:copy函数。
复制代码 代码如下:
/**
* deldir
*/
$dirname = 'a';
function deldir($dirname) {
$ds = opendir($dirname);
while (false !== ($file = readdir($ds))) {
$path = $dirname.'/'.$file;
if($file != '.' && $file != '..') {
if (is_dir($path)) {
deldir($path);
} else {
unlink($path);
}
}
}
closedir($ds);
return rmdir($dirname);
}
deldir($dirname);
核心:注意unlink删除的是带path的file。
复制代码 代码如下:
/**
* dirsize
*/
$dirname = "a";
function dirsize($dirname) {
static $tot;
$ds = opendir($dirname);
while (false !== ($file = readdir($ds))) {
$path = $dirname.'/'.$file;
if ($file != '.' && $file != '..') {
if(is_dir($path)) {
dirsize($path);
} else {
$tot = $tot + filesize($path);
}
}
}
return $tot;
closedir($ds);
}
echo dirsize($dirname);
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号