当前位置: 首页 > 图文教程 > 网络编程 > PHP > php获得一个文件夹下所有文件的文件名

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP 中的 php获得一个文件夹下所有文件的文件名


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 242 ::
收藏到网摘: n/a

以下为引用的内容:

php:

<?php
$dir = "/etc/php5/";

if (is_dir($dir))
{
if ($dh = opendir($dir))
{
       while (($file = readdir($dh)) !== false)
       {
         echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
       }
       closedir($dh);
}
}

ASP:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim thisPath,FSO,fileItem,allFolder
thisPath = Server.MapPath(Request.ServerVariables("SCRIPT_NAME")) '得到ASP文件的路径
Set FSO = createobject("scripting.filesystemobject")'创建FSO对像
Set allFolder = FSO.GetFile(thisPath).parentfolder.files '得到ASP所在目录的父级对像,它就包括了这个ASP和这个文件夹下的其它文件。thisPath当然可以自定义。

'下面是生成xml文件:

Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")'开始输出XML
Response.ContentType = "text/XML"
Response.Write("<path>")
For Each fileItem In allFolder '遍历整个对像中的元素
   If lcase(right(fileItem.name,4))=".jpg" Then '如果后缀是JPG,这是可以判断后缀。
   Response.Write("<url>"+fileItem.name+"</url>")'就把它的文件名输出为XML的一个新节点
   End If
Next
Response.Write("</path>")
Response.End()
%> '这是从blueidea-flash里学来的。呵呵。记录一下,防备忘记。