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下判断数组中是否存在相同的值array_unique

array_unique(PHP 4 >= 4.0.1, PHP 5) array_unique -- 移除数...

PHP目录操作实例总结

PHP目录操作实例总结

本文实例总结了PHP目录操作方法。分享给大家供大家参考,具体如下: 目录操作 新建目录:mkdir(路径,权限,递归创建) 删除目录:rmdir() 移动(改名):rename() 获取...

php获取是星期几的的一些常用姿势

一般有时在页面上需要显示是星期几,需要根据日期进行计算。 这边整理了几个相关的姿势,先来最终封装好的方法 /** * 一个通用的函数, 获取是星期几 * * @param $d...

php7安装mongoDB扩展的方法分析

本文讲述了php7安装mongoDB扩展的方法。分享给大家供大家参考,具体如下: 这里我们使用pecl命令来安装 首先来到php7的安装目录 $ /usr/local/php7/bi...

深入理解curl类,可用于模拟get,post和curl下载

如下所示:复制代码 代码如下:<?phpclass Curl { /*  * get 方式获取访问指定地址  * @param  strin...