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;
}

相关文章

执行、获取远程代码返回:file_get_contents 超时处理的问题详解

天气终于晴了,但问题来了。在实现两个站点间用户数据同步,当使用php函数 file_get_contents抓取执行远程页面时,如果连接超时将会输出一个Fatal Error或相当的慢,...

PHP fclose函数用法总结

php fclose()函数 语法 作用:关闭一个打开文件 语法: fclose(file) 参数: file 必需。规定要关闭的文件。 说明:如果成功则返回 true,否则返回...

php实现parent调用父类的构造方法与被覆写的方法

本文实例讲述了php实现parent调用父类的构造方法与被覆写的方法。分享给大家供大家参考。具体分析如下: 覆写:被重新设计。 在子类中定义构造方法时,需要传递参数给父类的构造方法,否则...

PHP写入WRITE编码为UTF8的文件的实现代码

<?php  $f=fopen("test.txt", "wb");  $text=utf8_encode("顨!");  // ...

采用header定义为文件然后readfile下载(隐藏下载地址)

复制代码 代码如下:<?php function sendFile($fileName, $fancyName = '', $forceDownload = true, $spee...