We encounter the need to convert picture files when using the PHP language. If you implement batch conversion, you can save a lot of time. Here we will give you a specific explanation about the PHPCB batch conversion method.
Recently need to tidy up a whole station of PHP code specifications view, a few days ago found PHPCB tidy view is very good, but there is a disadvantage is not batch processing, the use of the process found PHPCB is a CMD program, immediately think of PHP system function call cmd, think about doing, The following is a PHPCB batch conversion PHP Program:
Copy Code code as follows:
<?
header ("content-type:text/html; charset=gb2312 ");
define (' Root_path ', DirName (__file__));
$topath = "WW"; To format a view's directory name, do not forward or backward "/"
$path =root_path. " /". $topath;
$arr =get_all_files ($path);
for ($i =0; $i <count ($arr); $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));
}
?>
PHPCB Batch Conversion method: Put the PhpCB.exe in the windows/system32/Directory, PHP execution program and the folder to be converted to the same level of path, first configure the $topath, and then access the program in the browser, no results output.