Viewing file: addpathserver.php (2.01 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?PHP function update_file ($fpath, $defaultval) { $retval = false; if (file_exists($fpath)) unlink($fpath); if (($handle = fopen($fpath, "wb"))) { if (fwrite($handle, $defaultval) === FALSE) { if ($handle) fclose($handle); } else { fclose($handle); $retval = true; } } return $retval; } function folder_writable ( ) { $retval = false; $file_name = "testwrite_" . time() . ".txt"; if (($handle = fopen($file_name, "wb"))) { $retval = true; fclose($handle); unlink($file_name); } return $retval; } $save_file = '../global0.php'; $server_path="http://".$server_path."/mis/version/admin/send.php"; $new_path="http://".$new_path."/mis/version/admin/send.php"; if($method=="editpath"){ $server_path=$new_path; } if (folder_writable()) { $content = implode("", @file($save_file)); $pattern = "/(\\\$GLOBALS\[\\\"SERVER_PATH\\\"\]\s\=\s)(\\\")(.*)(\\\")(\;)/"; $replaceses = $server_path; if (preg_match($pattern,$content)){ //echo "match"; $newcontent = preg_replace($pattern, "\${1}\${2}$replaceses\${4}\${5}", $content); if (update_file($save_file, $newcontent) == true) { if($method=="addpath"){ echo "<meta http-equiv='refresh' content='0; URL=updatefile.php'>"; }else if($method=="editpath"){ ?> <script language="javascript1.2"> window.close(); window.opener.location.href="updatefile.php"; </script> <? } }else{ echo "<div align=\"center\">ไม่สามารถแก้ไขชื่อเครื่องได้</div>"; exit; } }else{ //not match echo "<div align=\"center\">ไม่สามารถแก้ไขชื่อเครื่องได้</div>"; exit; } } else { echo "<div align=\"center\">".getcwd() . " cannot writable!</div>"; exit; }
?>
|