在 aitecms 群里有網友抱怨了好幾天說本地的驗證碼一直無法顯示,后來聽說解決了,問其如何解決的,說是去除了文件 bom 就好了。后來百度到一篇文章也說 dedecms 的驗證碼不能顯示,某次解決了文件 bom 后竟然好了,于是本篇文章就顯得很重要了。
網上轉載的,出處已經不可考了,不知道原作者是誰,在這里先向作者表示感謝。
	代碼如下:
	 
				<?php    /*     * PHP批量去除bom頭代碼的小工具     * http://blog.kilvn.com/     */    if (isset($_GET['dir'])){ //設置文件目錄        $basedir=$_GET['dir'];    }else{        $basedir = '.';    }    $auto = 1;    checkdir($basedir);    function checkdir($basedir){        if ($dh = opendir($basedir)) {            while (($file = readdir($dh)) !== false) {                if ($file != '.' && $file != '..'){                    if (!is_dir($basedir."/".$file)) {                        echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>";                    }else{                        $dirname = $basedir."/".$file;                        checkdir($dirname);                    }                }            }        closedir($dh);        }    }    function checkBOM($filename) {        global $auto;        $contents = file_get_contents($filename);        $charset[1] = substr($contents, 0, 1);        $charset[2] = substr($contents, 1, 1);        $charset[3] = substr($contents, 2, 1);        if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {            if ($auto == 1) {                $rest = substr($contents, 3);                rewrite ($filename, $rest);                return ("<font color=red>BOM found, automatically removed.</font>");            } else {                return ("<font color=red>BOM found.</font>");            }        }        else return ("BOM Not Found.");    }    function rewrite($filename, $data) {        $filenum = fopen($filename, "w");        flock($filenum, LOCK_EX);        fwrite($filenum, $data);        fclose($filenum);    }			 | 		
新聞熱點
疑難解答