很多站长朋友们都不太清楚文件列表php,今天小编就来给大家整理文件列表php,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php 查询文件夹内有多少个文件夹 2、 怎么用php获得一个空间里的所有文件名列表 3、 php列出目录下所有文件(包括子目录) 4、 PHP列出目录中的目录和文件的几种方法 5、 PHP如何遍历指定文件夹,获取所有文件列表并生成下载链接?? 6、 PHP 列出当前目录下所有文件(自身别列出来) php 查询文件夹内有多少个文件夹php查询文件夹内的文件个数:
//获取目录/文件列表
public function getDirFile( $Dir ){
if( is_dir($Dir) ){
$DirFileArray['DirList'] = $this->getDir( $Dir );
if( $DirFileArray ){
foreach( $DirFileArray['DirList'] as $Handle ){
$File = $Dir.DS.$Handle;
$DirFileArray['FileList'][$Handle] = $this->getFile( $File );
}
}
}else{
$DirFileArray[] = '[Path]:\''.$Dir.'\' is not a dir or not found!';
}
return $DirFileArray;
}
}
?>
怎么用php获得一个空间里的所有文件名列表通过函数遍历输出文件名称
<?php $d=opendir('./'); while($file=readdir($d)){ if(is_file($file)) echo $file,"\n"; } closedir($d);?>
php列出目录下所有文件(包括子目录)<?php
/**
* Goofy 2011-11-30
* getDir()去文件夹列表,getFile()去对应文件夹下面的文件列表,二者的区别在于判断有没有“.”后缀的文件,其他都一样
*/
//获取文件目录列表,该方法返回数组
function getDir($dir) {
$dirArray[]=NULL;
if (false != ($handle = opendir ( $dir ))) {
$i=0;
while ( false !== ($file = readdir ( $handle )) ) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." $file != ".."!strpos($file,".")) {
$dirArray[$i]=$file;
$i++;
}
}
//关闭句柄
closedir ( $handle );
}
return $dirArray;
}
//获取文件列表
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]="./imageroot/current/".$file;
if($i==100){
break;
}
$i++;
}
}
//关闭句柄
closedir ( $handle );
}
return $fileArray;
}
//调用方法getDir("./dir")……
?>
PHP列出目录中的目录和文件的几种方法<?php
/**
* PHP中列出目录中的目录和文件的几种方法
*/
//兼容PHP4和PHP5的写法
function getFileList($directory) {
$files = array();
if(is_dir($directory)) {
if($dh = opendir($directory)) {
while(($file = readdir($dh)) !== false) {
if($file != '.' $file != '..') {
$files[] = $file;
}
}
closedir($dh);
}
}
return $files;
}
//PHP5中的简单方法
function getFileList2($directory) {
$files = array();
if(is_dir($directory)) {
if($files = scandir($directory)) {
$files = array_slice($files,2);
}
}
return $files;
}
//使用PHP5面向对象的写法
function getFileList3($directory) {
$files = array();
try {
$dir = new DirectoryIterator($directory);
} catch (Exception $e) {
throw new Exception($directory . ' is not readable');
}
foreach($dir as $file) {
if($file->isDot()) continue;
$files[] = $file->getFileName();
}
return $files;
}
//测试代码
$dir = dirname(__FILE__);
var_dump(getFileList($dir));
?>
PHP如何遍历指定文件夹,获取所有文件列表并生成下载链接??试编写代码如下:
<?php
$dir="D:/WWW/ftp"; //指定的路径
$sitepath = '';
//遍历文件夹下所有文件
if (false != ($handle = opendir ( $dir ))) {
echo "$dir 目录下的文件列表:<BR/>";
$i = 0;
while (false !== ($file = readdir($handle))) {
if ($file != "." $file != ".." !is_dir($dir.'/'.$file)) {
echo '<a href="' . $sitepath . $file . '">'.$file. '</a><br/>';
}
}
//关闭句柄
closedir($handle);
}
?>
代码中需要提示的是:
如果是运行于互联网上,需要考虑文件的访问安全性。
运行截图:
PHP 列出当前目录下所有文件(自身别列出来)1、列出当前目录的文件、文件夹完整路径
ls
-1
|awk
i$0}'
i=`pwd`'/'
(注意:这里
ls
后面那是个数字
1
而不是字母
l)
2、列出当前目录及子目录的文件、文件夹完整路径
ls
-r
|awk
i$0}'
i=`pwd`'/'
2b)
列出当前目录及子目录下的文件夹完整路径
ls
-fr
|
grep
/$
|
sed
"s:^:`pwd`/:"
3、用find实现,好像运行要慢些
find
/
-name
"*.*"
-exec
ls
{}
\;
4、递归列出当前目录及子目录名称
ls
-fr
|
grep
/$
5、递归列出当前目录及子目录名称,包括相关属性
ls
-lr
|
grep
"^d"
#
drwxr-xr-x
3
idea
idea
4096
aug
2
2009
images
6、只列出当前目录下的子目录
用ls只列出子目录
ls
-d
*/
关于文件列表php的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于文件列表php 文件列表窗格是整个窗口中最大的什么区域的详细内容...