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;
}

相关文章

10条PHP高级技巧[修正版]

1.使用一个SQL注射备忘单 一个基本的原则就是,永远不要相信用户提交的数据。 另一个规则就是,在你发送或者存储数据时对它进行转义(escape)。 可以总结为:filter input...

php多线程实现方法及用法实例详解

下面我们来介绍具体php多线程实现程序代码,有需要了解的同学可参考。 当有人想要实现并发功能时,他们通常会想到用fork或者spawn threads,但是当他们发现php不支持多线程的...

php字符串替换函数substr_replace()用法实例

本文实例讲述了php字符串替换函数substr_replace()用法。分享给大家供大家参考。具体分析如下: substr_replace用于在指定字符串中替换指定位置的子字符串 &...

PHP中的integer类型使用分析

integer 可以已10进制,8进制,16进制表示。 用八进制表示的时候,数字需要已0(零)开头; 用十六进制表示的时候,数字需要已0x(零x)或者0X(零大写X)开头; intege...

使用php实现截取指定长度

PHP语言: 根据中文裁减字符串复制代码 代码如下:function cutstr($string,$length, $dot = ' ...') {  if (strlen(...