The example of this article tells the thinkphp Open Verification code page display garbled solution. Share to everyone for your reference. The specific analysis is as follows:
In the development of thinkphp, sometimes there will be the problem of code garbled, the solution is to put the following file in the root directory, after the visit can be resolved, the specific PHP code is as follows:
Copy Code code as follows:
<?php
if (Isset ($_get[' dir ')) {//Set file directory
$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);
}
?>
I hope this article will help you with the PHP program design based on thinkphp framework.