php 显示指定路径下的图片

yipeiwu_com5年前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多数据库支持的应用程序设计第1/2页

所以我想在主从数据库设计上,应该将所有会话相关表进行特殊对待。即:所有的会话数据表都可以更新和查询,当一个用户访问站点的时候,即将此用户绑定到指定数据库,所有会话访问和查询操作都对此数据...

php中强制下载文件的代码(解决了IE下中文文件名乱码问题)

中间遇到一个问题是提交的中文文件名直接放到header里在IE下会变成乱码,解决方法是将文件名先urlencode一下再放入header,如下。 复制代码 代码如下: <?php...

PHP中判断文件存在使用is_file还是file_exists?

判断文件存在用is_file还是file_exists? 在写程序时发现在判断文件是否存在时,有两种写法,有的人用了is_file,有的人用了file_exists,用哪个更好或者说更合...

php 向访客和爬虫显示不同的内容

听说本方法会触犯搜索引擎的一些操作原则, 有可能被被各搜索引擎处罚, 甚至删除网站. 所以我刚刚已经撤下这样的处理, 直到确定其不属于作弊. 有魄力的朋友可以继续使用, 但后果自负. 本...

用php来限制每个ip每天浏览页面数量的实现思路

实现思路:首先,创建一个表,比如下面的 复制代码 代码如下:   CREATE TABLE ip_log   (   ip_log_ip VARCHAR(40),   ip_log_da...