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下通过curl抓取yahoo boss 搜索结果的实现代码

1.编写curl类,进行网页内容抓取 复制代码 代码如下: class CurlUtil { private $curl; private $timeout = 10; /** * 初始...

PHP基于rabbitmq操作类的生产者和消费者功能示例

本文实例讲述了PHP基于rabbitmq操作类的生产者和消费者功能。分享给大家供大家参考,具体如下: 注意事项: 1、accept.php消费者代码需要在命令行执行 2、'usernam...

php使用PDO下exec()函数查询执行后受影响行数的方法

本文实例讲述了php使用PDO下exec()函数查询执行后受影响行数的方法。分享给大家供大家参考,具体如下: exec()方法返回执行后受影响的行数。 语法:int PDO::exec(...

php使用Jpgraph绘制饼状图的方法

php使用Jpgraph绘制饼状图的方法

本文实例讲述了php使用Jpgraph绘制饼状图的方法。分享给大家供大家参考。具体实现方法如下: <?php include ("src/jpgraph.php");...

POST一个JSON格式的数据给Restful服务实例详解

在Android/Java平台上实现POST一个json数据: JSONObject jsonObj = new JSONObject(); jsonObj.put("usernam...