Hi,
the problem might be that you use $onsite_url in the file_get_contents line instead of $onsite_dir. And you might need to add a slash between the directory and the filename.
Something like this:
<?PHP
$open = opendir($onsite_dir);
while (($check = readdir($open)) != false){
if ($check != "." && $check != "..") {
$thefile = "$onsite_dir/$check";
$read = "";
$msg = "";
if (!function_exists('file_get_contents')) {
$handle = fopen($thefile, "r");
if ($handle) {
$read = fread($handle, filesize($thefile));
fclose($handle);
} else {
$msg = "Error: Cannot read $thefile.";
}
} else {
$read = file_get_contents($thefile);
}
if (strlen($read)) {
$read = $php_start.$read;
$read = str_replace("<script", "<?php /* <script", $read);
$read = str_replace("</script>", "</script> */ ?>", $read);
$read .= $php_end;
if(!chmod($thefile, 0755)){
$msg = "Error: Cannot change permissions of file $thefile.";
} else {
if($open = fopen($thefile, "w")) {
if (!fwrite($open, $read)) {
$msg = "Error: Cannot write to file $handle.";
} else {
$msg = "Success: Successfully modified $thefile.";
}
fclose($open);
} else {
echo "Error: Cannot open file $thefile for writing.";
}
}
} else {
$msg = "Error: file $thefile is empty.";
}
echo "$msg<br>\n";
}
}
?>
Don't forget to use fclose() ...
Thomas