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自定义大小验证码的方法详解

复制代码 代码如下:<?phpfunction vCode($num=4,$size=20, $width=0,$height=0){    &nbs...

php抽象类用法实例分析

本文实例讲述了php抽象类用法。分享给大家供大家参考。具体如下: <?php /* * abstract * 抽象类: * 1、至少有一个抽象方法(没有具体实现的...

PHP上传图片时判断上传文件是否为可用图片的方法

本文实例讲述了PHP上传图片时判断上传文件是否为可用图片的方法。分享给大家供大家参考,具体如下: 这里利用getimagesize函数: function isImage($file...

PHP实现事件机制的方法

本文实例讲述了PHP实现事件机制的方法。分享给大家供大家参考。具体如下: <?php /** * 事件 */ class Event { private $callb...

PHP中exec与system用法区别分析

本文实例讲述了PHP中exec与system用法区别,分享给大家供大家参考之用。具体方法如下: 一般来说,在PHP中调用外部命令,可以用exec及system来实现: system()...