Changeset 17489


Ignore:
Timestamp:
2008/08/03 14:57:49 (16 years ago)
Author:
nanasess
Message:

無効なファイルポインタが渡された場合に無限ループするバグ修正(#311)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/util/SC_Utils.php

    r17455 r17489  
    10211021    } 
    10221022 
     1023    /** 
     1024     * テキストファイルの文字エンコーディングを変換する. 
     1025     * 
     1026     * $filepath に存在するテキストファイルの文字エンコーディングを変換する. 
     1027     * 変換前の文字エンコーディングは, mb_detect_order で設定した順序で自動検出する. 
     1028     * 変換後は, 変換前のファイル名に「enc_」というプレフィクスを付与し, 
     1029     * $out_dir で指定したディレクトリへ出力する 
     1030     * 
     1031     * TODO $filepath のファイルがバイナリだった場合の扱い 
     1032     * TODO fwrite などでのエラーハンドリング 
     1033     * 
     1034     * @access public 
     1035     * @param string $filepath 変換するテキストファイルのパス 
     1036     * @param string $enc_type 変換後のファイルエンコーディングの種類を表す文字列 
     1037     * @param string $out_dir 変換後のファイルを出力するディレクトリを表す文字列 
     1038     * @return string 変換後のテキストファイルのパス 
     1039     */ 
    10231040    function sfEncodeFile($filepath, $enc_type, $out_dir) { 
    10241041        $ifp = fopen($filepath, "r"); 
    10251042 
    1026         $basename = basename($filepath); 
    1027         $outpath = $out_dir . "enc_" . $basename; 
    1028  
    1029         $ofp = fopen($outpath, "w+"); 
    1030  
    1031         while(!feof($ifp)) { 
    1032             $line = fgets($ifp); 
    1033             $line = mb_convert_encoding($line, $enc_type, "auto"); 
    1034             fwrite($ofp,  $line); 
    1035         } 
    1036  
    1037         fclose($ofp); 
    1038         fclose($ifp); 
    1039  
     1043        // 正常にファイルオープンした場合 
     1044        if ($ifp !== false) { 
     1045 
     1046            $basename = basename($filepath); 
     1047            $outpath = $out_dir . "enc_" . $basename; 
     1048 
     1049            $ofp = fopen($outpath, "w+"); 
     1050 
     1051            while(!feof($ifp)) { 
     1052                $line = fgets($ifp); 
     1053                $line = mb_convert_encoding($line, $enc_type, "auto"); 
     1054                fwrite($ofp,  $line); 
     1055            } 
     1056 
     1057            fclose($ofp); 
     1058            fclose($ifp); 
     1059        } 
     1060        // ファイルが開けなかった場合はエラーページを表示 
     1061          else { 
     1062              SC_Utils::sfDispError(''); 
     1063              exit; 
     1064        } 
    10401065        return     $outpath; 
    10411066    } 
     
    14311456                    break; 
    14321457                } 
    1433                  
     1458 
    14341459                mb_ereg("^(.*[\/])(.*)",$data_, $matches); 
    14351460                $data=$matches[2]; 
Note: See TracChangeset for help on using the changeset viewer.