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 5.5 创建和验证哈希最简单的方法详解

我们首先讨论password_hash()函数。这将用作创建一个新的密码的哈希值。它包含三个参数:密码、哈希算法、选项。前两项为必须的。你可以根据下面的例子来使用这个函数:复制代码 代码...

PHP 的ArrayAccess接口 像数组一样来访问你的PHP对象

复制代码 代码如下: interface ArrayAccess boolean offsetExists($index) mixed offsetGet($index) void of...

PHP实现逐行删除文件右侧空格的方法 原创

本文实例讲述了PHP实现逐行删除文件右侧空格的方法。分享给大家供大家参考,具体如下: 在编辑整理代码的过程中发现网上的一些代码经常会有不少的右侧空格,偶尔会影响到代码的排版与阅读,所以写...

php 面试碰到过的问题 在此做下记录

代码优化 复制代码 代码如下: for($i=0;$i<8;$i++){ array_push($week,$arr); } 复制代码 代码如下: for($i=0;$i<...

PHP实现仿百度文库,豆丁在线文档效果(word,excel,ppt转flash)

本文实例讲述了PHP实现仿百度文库,豆丁在线文档效果。分享给大家供大家参考,具体如下: 由于项目要实现类似百度文库的功能,又是我一个人做的项目,所以就想到找免费的现成的来使用。在网上找到...