如何用PHP更新不同目录中的多个PHP文件与更新的PHP文件
问题描述:
如何用不同目录中的多个PHP文件用相同的PHP文件替换为PHP例如我如何替换示例中的所有index.php
文件1与index.php
文件实施例2中如何用PHP更新不同目录中的多个PHP文件与更新的PHP文件
实施例1页的URL值
/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
实施例2的URL值
/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
答
您应该使用重命名功能(http://php.net/manual/en/function.rename.php)
要使用它,首先解析目录内容:
function renameFilesInDir($dirName) {
$dir = opendir($dirName);
while ($file = readdir($dir)) {
if (is_file($dirName.$file)) {
// Rename the File
}
}
closedir($dir);
}
祝您好运!
我不明白你的问题。你想从命令行使用PHP脚本重命名文件吗? – thomasmalt 2010-10-06 11:39:01
我想用新的index.php文件的更新版本替换所有旧的index.php文件 – HELP 2010-10-06 11:42:03
此线程可以帮助您:http://stackoverflow.com/questions/3853113/shell-script-for-renaming- and-relocating-the-files/3853166#3853166 – Amirshk 2010-10-06 11:44:39