php 显示指定路径下的图片

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

function getAllDirAndFile($path)
{
if(is_file($path))
{
if(isImage($path))
{
$str="";
$str.='<table style="border:solid 1px blue;" width="95%">';
$str.="<tr>";
$path=iconv("gb2312","utf-8",$path);
$str.="<td width=80%>".$path."</td><td width=15%><img src=".$path." style='width:50px;height:50px;'></td>";
$str.="</tr>";
$str.="</table>";
echo $str;
}
}
else
{
$resource=opendir($path);
while ($file=readdir($resource))
{
if($file!="." && $file!="..")
{
getAllDirAndFile($path."/".$file);
}
}
}
}

function isImage($filePath)
{
$fileTypeArray=array("jpg","png","bmp","jpeg","gif","ico");
$filePath=strtolower($filePath);
$lastPosition=strrpos($filePath,".");
$isImage=false;
if($lastPosition>=0)
{
$fileType=substr($filePath,$lastPosition+1,strlen($filePath)-$lastPosition);
if(in_array($fileType,$fileTypeArray))
{
$isImage=true;
}
}
return $isImage;
}

相关文章

探讨PHP函数ip2long转换IP时数值太大产生负数的解决方法

【造成原因】:Because PHP's integer type is signed, and many IP addresses will result in negative in...

php验证码生成器

现在很多网站都有实现用户集。然而为了防止机器人的网络攻击。限制登陆或者注册是有必要的。 在注册和登陆时强制要求输入一个机器难以识别的字符串集是一个不错的选择。虽然不能解决根本问题,但至...

用 PHP5 轻松解析 XML

用 sax 方式的时候,要自己构建3个函数,而且要直接用这三的函数来返回数据,要求较强的逻辑。在处理不同结构的 xml 的时候,还要重新进行构造这三个函数,麻烦! 用 dom 方式,倒是...

php读取文件内容的方法汇总

本文实例汇总了php读取文件内容的方法。分享给大家供大家参考。具体如下: 这里汇总php读取文件内容的五种方法。实际应用当中,请注意关闭 fclose($fp); 第一种方法:fread...

基于PHP文件操作的详解

知识点简介:1.判断文件或目录是否存在bool复制代码 代码如下:file_exists(string filename)  2.取得文件名复制代码 代码如下:basename...