比如JPG就有两种类型:
image/jpeg,image/pjpeg
好象不是一一对应的关系?

解决方案 »

  1.   

    都是image类型的,
    差不多的
      

  2.   

    function get_file_ext( $filename ) { 
    ereg( ".*\.([a-zA-z0-9]{0,5})$", $filename, $regs ); 
    return( $regs[1] ); 
    } and pass that to this: function get_file_type($f_ext) { 
    $image_exts = array (".jpg", ".gif", ".png"); 
    $text_exts = array (".htm", ".html", ".txt"); 
    $arr_size = sizeof($image_exts); 
    for($gft_count=0;$gft_count<$arr_size;$gft_count++){ 
          if ($image_exts[$gft_count] == $f_ext) { 
                  $file_type = "image"; 
                   } 

    $arr_size = sizeof($text_exts); 
    for ($gft_count=0;$gft_count<$arr_size;$gft_count++){ 
           if ($text_exts[$gft_count] == $f_ext) { 
                   $file_type = "text"; 
                   } 

    if ($file_type = "") { $file_type = "unknown"; } 
    return( $file_type ); 

      

  3.   

    function get_file_type($filename) {
    ereg( ".*\.([a-zA-z0-9]{0,5})$", $filename, $regs );
    $f_ext = $regs[1];$types['image'] = array ('jpg', 'gif','png');
    $types['text'] = array ('html', 'htm', 'text');
    $types['music'] = array ('mp3', 'mpeg3');
    foreach ($types as $k => $v) {
    if (in_array($f_ext, $v)) {
    return $k;
    break;
    }
    }
    echo 'type-unknown';
    }and in your readdir loop you do:
    get_file_type($file)