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中字符查找函数strpos、strrchr与strpbrk用法

本文实例讲述了php中字符查找函数strpos、strrchr与strpbrk用法。分享给大家供大家参考。具体如下: ① strpos() 函数返回字符串在另一个字符串中第一次出现的位置...

thinkphp jquery实现图片上传和预览效果

thinkphp jquery实现图片上传和预览效果

先上效果图: 那个file按钮样式先忽略 点击选择图片(浏览),随便选一张图片 js代码如下 //上传图片立即预览 function PreviewImage(imgFil...

PHP及Zend Engine的线程安全模型分析

PHP及Zend Engine的线程安全模型分析

不知道怎么回事总是令人不舒服的,因此我通过阅读源码和查阅有限的资料简要了解一下相关机制,本文是我对研究内容的总结。 本文首先解释了线程安全的概念及PHP中线程安全的背景,然后详细研究了P...

php实现倒计时效果

php实现倒计时效果

现在很多的团购网站上都有剩余时间的显示。显示剩余时间可以使用Javascript来实现,但是我们会发现使用Javascript来实现的话不安全,因为Javascript获取的是客户端的时...

详解PHP对数组的定义以及数组的创建方法

传统上把数组(array)定义为一组有某种共同特性的元素,这里的共同特性包括相似性(车模、棒球队、水果类型等)和类型(例如所有元素都是字符串或整数)等,每个元素由一个特殊的标识符来区分,...