开发者

How can I replace multiple PHP files in different directories with an updated PHP file using PHP

开发者 https://www.devze.com 2023-01-18 18:42 出处:网络
How can I replace multiple PHP files in different directories with the same PHP file using PHP for example, How do I replace all the index.php files in Example 1 with the index.php file in Example 2

How can I replace multiple PHP files in different directories with the same PHP file using PHP for example, How do I replace all the index.php files in Example 1 with the index.php file in Example 2

Example 1 url values

/files/user-2/a/index.php
/files/user-12/a/index.php
/files/user-23/a/index.php
/files/user-232/a/index.php
/files开发者_如何学编程/user-2232/a/index.php

Example 2 url values

/files/user-2/a/index.php
/files/user-12/a/index.php
/files/user-23/a/index.php
/files/user-232/a/index.php
/files/user-2232/a/index.php


You should use the rename function ( http://php.net/manual/en/function.rename.php )

To use it, begin by parsing the dir content :

function renameFilesInDir($dirName) {

    $dir = opendir($dirName);

    while ($file = readdir($dir)) {

        if (is_file($dirName.$file)) {

            // Rename the File  

        }

    }

    closedir($dir);

}

Good Luck !

0

精彩评论

暂无评论...
验证码 换一张
取 消