In-depth analysis of phpCB batch conversion code examples

Source: Internet
Author: User
This article provides a detailed analysis of the sample code for batch phpCB conversion. For more information, see

This article provides a detailed analysis of the sample code for batch phpCB conversion. For more information, see

We need to convert image files when using PHP. Batch conversion can save a lot of time. Next we will explain the methods for batch phpCB conversion.

Recently, we need to organize a full-site php code specification view. A few days ago, we found that the phpCB specification view is very good. The Hong Kong virtual host, however, has the disadvantage that it cannot be processed in batches. Hong Kong Space, during the use process, we found that phpCB is a CMD program, and immediately thought of php's system function calling cmd. The following is a php program for batch phpCB conversion:

The Code is as follows:


<?
Header ("Content-type: text/html; charset = gb2312 ");
Define ('root _ path', dirname (_ FILE __));
$ Topath = "ww"; // The Directory Name of the view to be formatted. Do not "/"
$ 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 batch phpCB conversion: Put phcmd.exe in the windows/system32/directory, put the php executable program and the folder to be converted in the same level path, first configure $ topath, then, access the program in the browser. There is no result output in the Hong Kong Space.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.