I'd like to process a form that passes a file and checks to see if the file exists, and if so, I'd like to throw a popup which asks the user if the file can be overwritten. So I'm just trying to use Javascript's confirm() function which passes a true/false back to PHP to update the fields. There's a catch 22 because what I'm basically trying to do is pass a variable between PHP and Javascript which I know I can't do. So here's the portion I've got when the user has passed the form over to be processed and checking the status of the file:
if (file_exists( $file_dir . '/' . $_FILES['file']['name'] )) {
echo "
<script>
if (!confirm('This file already exists...Overwrite File?')) {
location='FormRetrieve_TestIssues.php?id=$ID&sort_by=ID&sort_asc=0&formtype=UPDATE&kc_tbl=$kc_tbl';
}
</script>";
}
if ( $FILES['file']['name'] != "") {
move_uploaded_file( $FILES['file']['tmp_name'], $file_dir . '/' . $_FILES['file']['name'] );
$file_name=$_FILES['file']['name'];
$sql = "update $kc_tbl SET file='$file_name' where ID=".$ID;
$sql_exec = odbc_exec( $cnx, $sql );
}
And I thought that if the user backs out of overwriting the file, that I would use Javascript to just redirect out of the current page and stop processing it and go back to the original form. But the rest of the PHP code ends up executing anyway and I realize the Javascript won't stop this from happening. Any way I can do this on the form page before submitting?