Home >Backend Development >PHP Tutorial >PHP modifies the program code of the file and all file suffixes under the file_PHP tutorial

PHP modifies the program code of the file and all file suffixes under the file_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:41:491003browse

  1. //This file and the file in the directory to be changed are placed in the same folder.
  2. //The main purpose of the code is to change the file suffix in batches. Since the Taobao data package image types are different, it needs to be changed to the appropriate one
  3. define("STA",".gif");/ /Original file format
  4. define("END",".jpg");//Format to be changed
  5. $dir = "./";
  6. $ arr = allfile($dir);
  7. foreach($arr as $t)
  8. {
  9. $t=str_replace(".//","",$ t);
  10. if(substr_count($t,STA)>0)
  11. {
  12. $f2=str_replace(STA,"",$t);
  13. rename($t,$f2.END);
  14. }
  15. }
  16. //Get all files in the directory Function
  17. function allfile($dir)
  18. {
  19.               $files=array();                                                                                                            
  20. {
  21.                                                                                                                                                                           if($handle) {
  22. While (FALSE! == ($ File = Readdir ($ Handle)) {
  23. if ($ file! =. && $ file! = ..) {
  24. $filename = $dir . "/" . $file; $filename;
  25.                                                                                 {
  26.                                                                                                                                                                                                                        >                                                                                                                                                                                                                                                      .
  27.                 closedir($handle);                                                                            >
  28. http://www.bkjia.com/PHPjc/486104.html
  29. www.bkjia.com
  30. true
  31. http: //www.bkjia.com/PHPjc/486104.html
  32. TechArticle
  33. ?php //This file is placed in the same folder as the file in the directory to be changed. //The main purpose of the code is to batch change the file suffix. Due to the different types of Taobao data packet pictures, it is necessary to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn