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读取文件内容的三种可行方法示例介绍

php读取文件内容的三种方法: //**************第一种读取方式***************************** 复制代码 代码如下: header("conte...

基于PHP文件操作的详解

知识点简介:1.判断文件或目录是否存在bool复制代码 代码如下:file_exists(string filename)  2.取得文件名复制代码 代码如下:basename...

浅析php中jsonp的跨域实例

我们现在www.test.com这个域名下面有这么个html文件testjsonp.html:复制代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DT...

深入讲解PHP的对象注入(Object Injection)

深入讲解PHP的对象注入(Object Injection)

前言 虽然这篇文章叫做PHP对象注入,但是本质上还是和PHP的序列化的不正确使用有关。如果你阅读了PHP中的SESSION反序列化机制对序列化就会有一个大致的认识。PHP对象注入其实本质...

PHP实现上传图片到数据库并显示输出的方法

PHP实现上传图片到数据库并显示输出的方法

本文实例讲述了PHP实现上传图片到数据库并显示输出的方法。分享给大家供大家参考,具体如下: 1. 创建数据表 CREATE TABLE ccs_image ( id int(4)...