当前位置: 首页 > 图文教程 > 网络编程 > PHP > php 显示指定路径下的图片

PHP
轻松实现用PHP编写PDF文档生成器(一)
轻松实现用PHP编写PDF文档生成器(二)
php下载文件,PHP下载文件源码
一行PHP代码检测字符中中文汉字个数
用PHP开发多任务应用程序
怎样用PHP实现网站防盗链
PHP.MVC之模板标签系统(一)
PHP.MVC之模板标签系统(二)
PHP.MVC之模板标签系统(三)
PHP.MVC之模板标签系统(五)
PHP.MVC之模板标签系统(四)
linux/unix下使用php来做守护进程
PHP多文件上传类,实现php多文件上传
PHP编实现程动态图像的创建
利用PHP伪造http头(referer)
常见的25个顶级PHP模板引擎
PHP生成带有雪花背景的验证码
PHP日常开发中常用的一些小技巧
PHP + MySQL 分表减低数据库压力
PHP的语言层面的优化和代码优化

PHP 中的 php 显示指定路径下的图片


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 90 ::
收藏到网摘: n/a

给一个路径,得到她下面的图片,并显示出来的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;
}