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 /*我的程序在国外的SREVER上,自己编的程序存放到哪,我很难记清。 所以编了一个简单的目录递归函数,查看我的程序,很方便的。 */ function tree($d...

关于php 高并发解决的一点思路

我的思路如下(伪代码): sql1:查询商品库存 if(库存数量 > 0) { //生成订单... sql2:同时库存-1 } 当没有并发时,上面的流程看起来是再正常不过了...

PHP基于接口技术实现简单的多态应用完整实例

PHP基于接口技术实现简单的多态应用完整实例

本文实例讲述了PHP基于接口技术实现简单的多态应用。分享给大家供大家参考,具体如下: <?php //实现多态的一个简单实例 interface USB{ //接口...

PHP编程实现多维数组按照某个键值排序的方法小结【2种方法】

PHP编程实现多维数组按照某个键值排序的方法小结【2种方法】

本文实例讲述了PHP编程实现多维数组按照某个键值排序的方法。分享给大家供大家参考,具体如下: 实现对多维数组按照某个键值排序的两种解决方法(array_multisort和array_s...

php使用escapeshellarg时中文被过滤的解决方法

本文分析了php使用escapeshellarg时中文被过滤的解决方法。分享给大家供大家参考。具体如下: 一、问题: 同样的代码,发现通过 localhost/index.php 访问,...