我在思索,一些批量采集到的图片该如何放入网站,现在想到的就是遍历目录,然后显示到网站中。于是就简单查询了一下文件、文件夹的遍历,可以看看代码,一个示例就学会怎么使用,今后直接来找。
<?php/*** 遍历文件夹下的所有文件*/function getFile($dir) {$fileArray[]=NULL;if (false != ($handle = opendir ( $dir ))) {$i=0;while ( false !== ($file = readdir ( $handle )) ) {//去掉"“.”、“..”以及带“.xxx”后缀的文件if ($file != "." && $file != ".."&&strpos($file,".")) {$fileArray[$i]=$file;$i++;}}//关闭句柄closedir ( $handle );}return $fileArray;}$file = "./";$data = getFile($file);//var_dump($data);/*** 遍历文件夹展示所有的文件和目录*/function dirList($dir_path = '') {if(is_dir($dir_path)) {$dirs = opendir($dir_path);if($dirs) {while(($file = readdir($dirs)) !== false) {if($file !== '.' && $file !== '..') {if(is_dir($file)) {echo $dir_path . '/' . $file . '<br>';dirList($dir_path . '/' . $file);} else {echo $dir_path . '/' . $file . '<br>';}}}closedir($dirs);}} else {echo '目录不存在!';}}//dirList('D:/wwwroot/www.kekc.cn');<?php /** * 遍历文件夹下的所有文件 */ function getFile($dir) { $fileArray[]=NULL; if (false != ($handle = opendir ( $dir ))) { $i=0; while ( false !== ($file = readdir ( $handle )) ) { //去掉"“.”、“..”以及带“.xxx”后缀的文件 if ($file != "." && $file != ".."&&strpos($file,".")) { $fileArray[$i]=$file; $i++; } } //关闭句柄 closedir ( $handle ); } return $fileArray; } $file = "./"; $data = getFile($file); //var_dump($data); /** * 遍历文件夹展示所有的文件和目录 */ function dirList($dir_path = '') { if(is_dir($dir_path)) { $dirs = opendir($dir_path); if($dirs) { while(($file = readdir($dirs)) !== false) { if($file !== '.' && $file !== '..') { if(is_dir($file)) { echo $dir_path . '/' . $file . '<br>'; dirList($dir_path . '/' . $file); } else { echo $dir_path . '/' . $file . '<br>'; } } } closedir($dirs); } } else { echo '目录不存在!'; } } //dirList('D:/wwwroot/www.kekc.cn');<?php /** * 遍历文件夹下的所有文件 */ function getFile($dir) { $fileArray[]=NULL; if (false != ($handle = opendir ( $dir ))) { $i=0; while ( false !== ($file = readdir ( $handle )) ) { //去掉"“.”、“..”以及带“.xxx”后缀的文件 if ($file != "." && $file != ".."&&strpos($file,".")) { $fileArray[$i]=$file; $i++; } } //关闭句柄 closedir ( $handle ); } return $fileArray; } $file = "./"; $data = getFile($file); //var_dump($data); /** * 遍历文件夹展示所有的文件和目录 */ function dirList($dir_path = '') { if(is_dir($dir_path)) { $dirs = opendir($dir_path); if($dirs) { while(($file = readdir($dirs)) !== false) { if($file !== '.' && $file !== '..') { if(is_dir($file)) { echo $dir_path . '/' . $file . '<br>'; dirList($dir_path . '/' . $file); } else { echo $dir_path . '/' . $file . '<br>'; } } } closedir($dirs); } } else { echo '目录不存在!'; } } //dirList('D:/wwwroot/www.kekc.cn');
© 版权声明
THE END
暂无评论内容