简体   繁体   中英

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

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM