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数组指针操作详解

数组指针的操作: 移动数组指针的操作: Next() 向下 同时会获得当前元素的值。 Prev() 向上同时会获得当前元素的值。 End() 移动到最后一个元素单元 获得最后一个元素的值...

jQuery+PHP实现的掷色子抽奖游戏实例

jQuery+PHP实现的掷色子抽奖游戏实例

本文实例讲述了jQuery+PHP实现的掷色子抽奖游戏详细步骤。分享给大家供大家参考。具体分析如下: 该游戏是以大富翁游戏为背景,综合运用jQuery和PHP知识,设计出以掷色子点数来达...

PHP异常Parse error: syntax error, unexpected T_VAR错误解决方法

其实,这是一个非常容易解决掉的问题。在我看来,似曾相识,呵呵,最近学JavaScript可是学会了使用var声明变量。 其实,在PHP中根本不需要使用var声明的,但是当一个变量作为一个...

PHP创建单例后台进程的方法示例

本文实例讲述了PHP创建单例后台进程的方法。分享给大家供大家参考,具体如下: 可以通过如下语句启动一个PHP后台进程: $command = " php script.php ";...

PHP面相对象中的重载与重写

重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。Overloaded的方法是可以改变返回值的类型。也就是说,重载的返回值类...