本文实例讲述了PHP文件与目录操作。分享给大家供大家参考,具体如下:
文件目录相关函数
"; } } } } } }else{ echo"对不起,这个目录不存在."; } } $allowedtypes=array("txt","html"); outputcurfiles ($allowedtypes,"testfolder"); /////////////////////////////////////////////////// functionrecurdir ($thedir) { //First attempt to open the directory. try{ if($adir= opendir ($thedir)){ //扫描目录。 while(false !== ($anitem= readdir ($adir))){ //不统计目录中包含“.”或“..”的情况 if($anitem!="."&&$anitem!=".."){ //此时如果是一个目录,则缩进一点 //再去递归 if(is_dir($thedir."/".$anitem)){ ?>"; } } } }else{ thrownewexception ("Sorry, directory could not be openend."); } }catch(exception$e) { echo$e->getmessage(); } } echo"/////////////////////////////////////
"; recurdir("testfolder"); ////////////////////////////////////////////////////////////////// echo"
/////////////////////////////////////
"; functionsortfilesbydate ($thedir){ //首先,需要确保目录存在。 if(is_dir($thedir)){ //接着,我们使用scandir扫描此目录中的文件. $scanarray= scandir ($thedir); $finalarray=array(); //然后开始解析数组 //scandir()用“.”和“..”统计文件导航列表 //因此作为文件,我们不应该列出他们. for($i= 0;$i
http://m.bbyears.com/jiaocheng/117129.html
推荐访问:php文件怎么运行 php格式文件怎么打开 php读取文件内容