i am trying to code this script to scan my whole site for index.html files so i can replace them with a new one. i am using php5 on apache1, this script is not working, it was before i start it to add a counter, a protection, and some html tables. Can anybody re-code this script so it can work PLEASE, i really need this, i have 255 files to replace.
somebody suggested me to remove print and add echo instead, php5 issue, i cant try it right now because i dont have php on my server due to a bad server update. can sombody try it i really want to know if this script is working or not, just place some index.html files withing 2 or 3 directories and add an index.html you will to the others with in you DirectoryIndex and run test.php script, simple.
1) counter function
2) recursive function
3) replace function
4) display just ALL path that contains Index.html files
5) status if the file was replace or not
thats it.
Thanks!.
<?php
$path=$_SERVER['DOCUMENT_ROOT']; // <-- starting path
$replace="index.html"; // <-- replace all index.html files
$new="$path/modules/Replace/index.html"; // <-- replace with
$show_output=0; // <-- counter 0
function replace($file,$replace,$path,$new) {
// protecting the index.html in path $new
if ($file=="$replace") {
$newfile="$path/$file";
if ($newfile=="$new"); {
echo "<b>protected $newfile.</b><BR><BR>\n";
}
} else { // if $file isn't the $new file and failed to copy, show outputs
if ($file=="$replace") {
$newfile="$path/$file";
if (!copy($new, $newfile)) {
echo "failed to copy $newfile.";
}
} else {
print "<table width=\"100%\" style=\"color: #000080; background-color:
#F0F0F0; font-family:Verdana; font-size:8pt\" cellspacing=\"0\"
cellpadding=\"0\">";
print "<tr>";
function recursedir($path,$replace,$new,$show_output) {
$hndl=opendir($path); // <-- opening dir to scan for index.html
$output="";
while($file=readdir($hndl)) {
if ($file=='.' || $file=='..') continue;
$completepath="$path/$file";
if (is_dir($completepath)) {
recursedir($path.'/'.$file,$replace,$new,$show_output); // <-- recurse dirs/subdirs
$output .= "<tr><td width=\"50%\"><p align=\"left\">DIR:
$path/$file</p></td><td width=\"50%\"><p
align=\"left\">$status</p></td></tr>\n";
} else {
replace($file,$replace,$path,$new);
$output .= "<tr><td width=\"50%\"><p align=\"left\">
$path/$file</p></td><td width=\"50%\"><p
align=\"left\">$status</p></td><tr>\n";
}
if($show_output=="1"){
echo $output;
}
}
}
recursedir($path,$replace,$new,$show_output);
print "</tr>";
print "</table>";
}
}
}
?>