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 $_FILES中error返回值详解

$_FILES['file']['error']值 UPLOAD_ERR_OK: 0 //正常,上传成功 UPLOAD_ERR_INI_SIZE: 1 //上传文件大小超过服务器允许上传...

php实现的网络相册图片防盗链完美破解方法

本文实例讲述了php实现的网络相册图片防盗链完美破解方法。分享给大家供大家参考。具体如下: 网络相册图片防盗链破解程序 - PHP版 这个防盗链破解版可以完美破解当下比较流行的: 百度相...

php页面缓存ob系列函数介绍

这里有缓存技术的简单介绍:https://www.jb51.net/article/4965.htm   php页面缓存主要用到的是ob系列函数,如ob_start(),ob_end_f...

理解PHP中的stdClass类

相信大家跟我一样,会经常看到和下面很类似的PHP代码: 复制代码 代码如下:$user = new stdClass();$user->name = 'gouki'; 这样的代码,...

PHP中创建空文件的代码[file_put_contents vs touch]

I has passed a small test to check which function is faster to create a new file. file_put_co...