2020年4月14日
<?phpfunction getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);function getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}if(is_dir($fullpath)){$res =getdir($fullpath);$size += $res;}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);echo"<pre>";echo "mkdir 函数:<br>";$res=mkdir('./img/num/num2', 0, true);var_dump($res);echo"<hr>";echo"rmdir 函数:<br>";$res=rmdir('./img');$res=rmdir('./img/num/num2/num3');$res=rmdir('./img/num2');var_dump($res);echo"<hr>";echo"unlink 删除文件: <br>";$res=unlink('./img/image_emotion18.png');var_dump($res);echo"</pre>";php2<?phpfunction getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);function getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}if(is_dir($fullpath)){$res =getdir($fullpath);$size += $res;}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);echo"<pre>";echo "mkdir 函数:<br>";$res=mkdir('./img/num/num2', 0, true);var_dump($res);echo"<hr>";echo"rmdir 函数:<br>";$res=rmdir('./img');$res=rmdir('./img/num/num2/num3');$res=rmdir('./img/num2');var_dump($res);echo"<hr>";echo"unlink 删除文件: <br>";$res=unlink('./img/image_emotion18.png');var_dump($res);echo"</pre>";php3<?phpfunction getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);function getdir($path){$size= 0;$a=opendir($path);readdir($a);readdir($a);while($filename = readdir($a)){echo$filename,"<br>";$fullpath=$path . '/' .$filename;if(is_file($fullpath)){$size += filesize($fullpath);}if(is_dir($fullpath)){$res =getdir($fullpath);$size += $res;}}closedir($a);return $size;}$res = getdir('C:\phpstudy_pro\www\img');var_dump($res);echo"<pre>";echo "mkdir 函数:<br>";$res=mkdir('./img/num/num2', 0, true);var_dump($res);echo"<hr>";echo"rmdir 函数:<br>";$res=rmdir('./img');$res=rmdir('./img/num/num2/num3');$res=rmdir('./img/num2');var_dump($res);echo"<hr>";echo"unlink 删除文件: <br>";$res=unlink('./img/image_emotion18.png');var_dump($res);echo"</pre>";
笔记:
统计目录大小:
目录的大小是由目录下的所有文件组成(子目录下的文件)
写一段代码获取指定目录下面的所有文件(包含子目录下的文件)
第一步:获取指定文件夹的一级文件大小,先不管子目录内的文件
第二步:编写子文件夹遍历功能
建立与删除目录
mkdir 创建目录
rmdir 删除目录
unlink 删除文件
mkdir (地址[,权限[,递归创建]])
权限参数在window系统报废
