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 模板高级篇总结

如何使用PHP来快速地编写代码,模版似乎成了唯一的选择。但是一个PHPer最终应该坚持使用模版,放弃模版,还是使用自己的模版?     以下想法是...

PHP命名空间与自动加载机制的基础介绍

前言 include 和 require 是PHP中引入文件的两个基本方法。在小规模开发中直接使用 include 和 require 没哟什么不妥,但在大型项目中会造成大量的 incl...

深入了解PHP类Class的概念

例如,一个交通工具可以定义有颜色、轮胎数、制造商、型号和容量等性质,并定义有停止、前进、转弯和鸣笛等行为。在OOP术语中,实体的性质和行为的具体定义称为类(class)。 类的定义与创建...

PHP实现读取一个1G的文件大小

需求如下: 现有一个1G左右的日志文件,大约有500多万行, 用php返回最后几行的内容。 1. 直接采用file函数来操作 or file_get_content() 肯定报内存溢出注...

linux下删除7天前日志的代码(php+shell)

PHP版本: 复制代码 代码如下: /** * 删除7天前的日志 * @param $logPath */ function del7daysAgoLog($logPath) { if(...