When we use PHP language, we will encounter the need to convert image files. If you implement batch conversion, you can save a lot of time. Below we will explain in detail the method of batch conversion of phpCB.
Recently I need to organize a PHP code specification view for the entire site. I found phpCB a few days ago to organize the view very well, but there is a disadvantage that it cannot be processed in batches. During the use, I found that phpCB is a CMD program, and I immediately thought of it. The system function of php calls cmd, just do it when you think of it. The following is the php program for batch conversion of phpCB:
Copy the code The code is as follows:
< ?
header("Content-type: text/html; charset=gb2312");
define('ROOT_PATH', dirname(__FILE__));
$topath="ww"; //To format the directory name of the view, do not use "/" before or after
$path=ROOT_PATH."/".$topath;
$arr=get_all_files($path);
for($i =0;$i{
$phpext=fileext($arr[$i]);
if($phpext=="php")
{
$cmd="phpCB.exe ".$arr[$i]." > ".$arr[$i].".phpCB";
system($cmd);
unlink($arr[$i]);
@rename($arr[$i].".phpCB",$arr[$i]);
}
}
function get_all_files( $path){
$list = array();
foreach(glob($path . '/*') as $item){
if(is_dir($item)){
$ list = array_merge($list , get_all_files( $item ));
} else {
$list[] = $item;
}
}
return $list;
}
function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1, 10));
}
?>
How to use phpCB batch conversion: Place phpCB.exe in the windows/system32/ directory, put the php execution program and the folder to be converted in the same path, configure $topath first, and then access this program in the browser , no result is output.
http://www.bkjia.com/PHPjc/327882.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327882.htmlTechArticleWhen we use PHP language, we will encounter the need to convert image files. If you implement batch conversion, you can save a lot of time. Below we will explain to you in detail about phpC...