hanling 发表于 2015-11-18 06:32:38

PHP编程----遍历目录得到图片文件并输出

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