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中错误日志的获取方法有很多种,下面我给大家简单介绍下遇到此类问题如何解决,下面通过代码给大家展示下,希望能够帮助到大家。 <?php error_reporti...

php常用经典函数集锦【数组、字符串、栈、队列、排序等】

php常用经典函数集锦【数组、字符串、栈、队列、排序等】

本文实例总结了php常用经典函数。分享给大家供大家参考,具体如下: 数组函数 数组操作 range(start,end) 创建一个数组,值从start开始,一直到end结束 如果r...

PHP面向对象五大原则之依赖倒置原则(DIP)详解

本文实例讲述了PHP面向对象五大原则之依赖倒置原则(DIP)。分享给大家供大家参考,具体如下: 什么是依赖倒置呢?简单地讲就是将依赖关系倒置为依赖接口,具体概念如下: 1.上层模块不应该...

php对象工厂类完整示例

本文实例讲述了php对象工厂类。分享给大家供大家参考,具体如下: <?php /** * 对象工厂 * @author flynetcn */ class Obj...

2017年最新PHP经典面试题目汇总(上篇)

1、双引号和单引号的区别 双引号解释变量,单引号不解释变量 双引号里插入单引号,其中单引号里如果有变量的话,变量解释 双引号的变量名后面必须要有一个非数字、字母、下划线的特...