|
<?php $imgtype=array('bmp','jpg','jpeg','png','gif'); //初始化图片文件扩展名 $imgtype_count=count($imgtype); //计算共有多少图片扩展名 $path="."; //设定目录 $handle=opendir($path); //打开目录 while ($file = readdir($handle)) //取得目录中的文件名{ if (is_dir($file)) {continue;} //如果$file为目录,则不做操作 $type = explode(".",$file); //分割字符串 $type=$type[1]; //得到文件扩展名 for($i=0;$i<$imgtype_count;$i++){ if($type==$imgtype[$i]) //判断文件扩展名是否为图片文件的扩展名,若是则做下列输出 { echo"<a href=".$path."/".$file." target=/"_blank/" alt=/"点击打开新窗口浏览/"><img src=".$path."/".$file." border=/"0/" onload=/"if(this.height>150) {this.height=150;this.width=150*this.width/this.height;}/"></a>/n"; } } } closedir($handle); //关闭目录 ?> 版权声明:本文为博主原创文章,未经博主允许不得转载。 |
|
|