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 !
精彩评论