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 session有效期问题

一个已知管用的方法是,使用session_set_save_handler,接管所有的session管理工作,一般是把session信息存储到数据库,这样可以通过SQL语句来删除所有过期...

WordPress中给媒体文件添加分类和标签的PHP功能实现

WordPress中给媒体文件添加分类和标签的PHP功能实现

从WordPress后台媒体库上传的媒体文件,不像文章那样可以给它指定分类和标签,但是很多时候我们又需要这样的功能,如一些下载站、图片站等。 媒体编辑页面的原始状态 很明显,在Wor...

解决php的“It is not safe to rely on the system’s timezone settings”问题

如果使用PHP5.3以上版本时,如果没有正确的配置php.ini就会出现PHP日期函数的错误。以前很多旧的PHP编程教程没有说到这个问题,所以不少读者会觉得困惑,下面笔者为大家讲述解决这...

PHP判断FORM表单或URL参数来的数据是否为整数的方法

PHP判断FORM表单或URL参数来的数据是否为整数,is_int函数对于FORM表单或URL参数过来的数据是没有办法判断是否是整数的,因为FORM过来的是字符串。 用is_numeri...

php文件下载处理方法分析

本文实例讲述了php文件下载的处理方法。分享给大家供大家参考。具体分析如下: php能够处理多种条件的文件下载,先来看下面示例: <?php header("Conte...