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 数组二分法查找函数代码

复制代码 代码如下:<?php //search函数 其中$array为数组,$k为要找的值,$low为查找范围的最小键值,$high为查找范围的最大键值 function sea...

CMSPRESS 10行代码搞定 PHP无限级分类2

超级无限分类 使用简单 效率极高 核心代码10行不到 另外 求这个分类的不足,和更高效简单的无限分类方法 ^_^ 核心代码如下 class Tool { static pu...

php输出指定时间以前时间格式的方法

本文实例讲述了php输出指定时间以前时间格式的方法。分享给大家供大家参考。具体分析如下: 比如说你需要在php中输出3天前,20分钟以前,可以参考下面的代码 function ago...

php用ini_get获取php.ini里变量值的方法

本文实例讲述了php用ini_get获取php.ini里变量值的方法。分享给大家供大家参考。具体分析如下: 要得到php.ini里的变量值,当然,你可以用phpinfo();来得到所有p...

php中json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案

PHP5.4才支持JSON_UNESCAPED_UNICODE这个参数,此参数是让中文字符在json_encode的时候不用转义,减少数据传输量。但在PHP5.3中,就得自己写个函数来实...