PHP File System
Chapter 10:
function save_file() {
global $filename, $filebody, $dir, $PHP_SELF;
if (file_exists("$dir/$filename")) {
echo "<SCRIPT>result =
confirm(\"Overwrite '$dir/$filename'?\");
if (!result) history.go(-1);</SCRIPT>";
}
if ($file = fopen("$dir/$filename", "w")) {
fputs($file, $filebody);
fclose($file);
}
else {
error_message("Can't save file $dir/$filename.");
}
echo "<SCRIPT>self.location.href='$PHP_SELF?dir=$di r& filename=$filename';</SCRIPT>";
}
When the Cancel button of the JavaScript Confirm() method is pressed, it will falls back to the previous page but it still overwrite the existing file. Why is that???
|