<?php
$a=system('dir /b');
foreach($a as $b){
$c=substr("$b", -3);
  if($c=="jpg"){
  echo $b;
  }
}
?>

解决方案 »

  1.   

    win下
    <?php 
    $a=system('dir /b'); 
    foreach($a as $b){ 
    $c=substr("$b", -3); 
      if($c=="jpg"){ 
      echo $b; 
      } 

    ?>linux下
    <?php 
    $a=system('ls'); 
    foreach($a as $b){ 
    $c=substr("$b", -3); 
      if($c=="jpg"){ 
      echo $b; 
      } 

    ?>如果有中文就用substring代替substr。但是注意,要在配置文件里打开substring支持。
      

  2.   

    <?php
    $dh = opendir('.');// 打开目录
    if(false === $dh) {
      echo 'opendir failed!';
      exit;
    }while(false !== ($file = readdir($dh))){// 读取
      if(!is_file($file)) 
        continue;
      
      if(function_exists('exif_imagetype')) {// 精确判断1,需要exif扩展
        if(IMAGETYPE_JPEG == exif_imagetype($file))
          echo $file."<br />\n";
      }elseif(function_exists('getimagesize')) {// 精确判断2
        $imageinfo = getimagesize($file);
        if(false === $imageinfo)
          continue;    if(IMAGETYPE_JPEG == $imageinfo[2])
          echo $file."<br />\n";
      }else {// 不精确判断,根据扩展名
        if('.jpg' == substr($file, -4) || '.jpeg' == substr($file, -5))
          echo $file."<br />\n";
      }
    }closedir($dh);
    ?>
      

  3.   

    <?php
    foreach(glob("*.jpg") as $filename)
    {
       echo $filename."<br>";
    }
    ?>