php 显示指定路径下的图片

yipeiwu_com5年前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 配置后台登录以及模板引入

PHP 配置后台登录以及模板引入

(1)项目下.env 是配置数据库的文件 DB_HOST=127.0.0.1 DB_DATABASE=blog DB_PREFIX=blog_ DB_USERNAME=root DB...

PHP经典面试题集锦

本文较为详细的分析了PHP经典面试题。分享给大家供大家参考。具体如下: 做了一下网络上的php题目,不知不觉做到现在.....把答案贴出来,供参考之用。 1、用PHP打印出前一天的时间格...

PHP 递归效率分析

而且是差了3倍的效率。所以,PHP中的递归一定要小心的对待。 最近写了一个快速排序的算法,发现PHP中的递归效率不能一刀切,在各种不同的服务器中,可能会表现不一样。 复制代码 代码如下:...

php类的定义与继承用法实例

本文实例讲述了php类的定义与继承用法。分享给大家供大家参考。具体如下: <?php /* * class */ class people { public...

PHP eval函数使用介绍

代码: eval("echo'hello world';"); 上边代码等同于下边的代码: echo"hello world"; 在浏览器中都输出:hello world 运用ev...