PHP 修改文件及文件下所有文件后缀的程序代码
Release: 2016-06-13 10:40:37
Original
1212 people have browsed it
- //本文件和要改变的目录下的文件 放在同一文件夹下。
- //代码主要的目的是 批量更改 文件后缀 由于淘宝数据包图片类型的不同 所以要改一下适合的
- define("STA",".gif");//原来的文件格式
- define("END",".jpg");//要改变的格式
- $dir = "./";
- $arr = allfile($dir);
- foreach($arr as $t)
- {
- $t=str_replace(".//","",$t);
- if(substr_count($t,STA)>0)
- {
- $f2=str_replace(STA,"",$t);
- rename($t,$f2.END);
- }
- }
-
- //获取目录下所有文件的函数
- function allfile($dir)
- {
- $files=array();
- if(is_file($dir))
- {
- return $dir;
- }
- $handle = opendir($dir);
- if($handle) {
- while(false !== ($file = readdir($handle))) {
- if ($file != . && $file != ..) {
- $filename = $dir . "/" . $file;
- if(is_file($filename)) {
- $files[] = $filename;
- }else {
- $files = array_merge($files, allfile($filename));
- }
- }
- } // end while
- closedir($handle);
- }
- return $files;
- }
- ?>
Statement of this Website
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31