blueman378 Posted April 4, 2008 Share Posted April 4, 2008 hi guys, well heres my code: <?php $dual = 0; $upload = "filename"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> function overwrite() { var response = confirm('The file "<?=$upload?>" already exists would you like to overwrite?'); if (overwrite) <?php $overwrite = 1; ?>; else <?php $overwrite = 0; ?>;}</SCRIPT> </head> <?php if ($dual == "1") { ?> <body onload="overwrite()"> <?php } else { ?> <body> <?php } echo $overwrite; ?> which works a bit, but i want the page to stop loading, that includes the server side stuff, till the javascript confirm has been run, is this possibnle? cheers Quote Link to comment Share on other sites More sharing options...
nogray Posted April 4, 2008 Share Posted April 4, 2008 Adding the a script tag will stop processing the page, so adding the confirmation in the head (you almost have it) will do the trick. Just remove the function so the confirm message shows up right away. The main issue is PHP runs before JavaScript exists, so you'll need to redirect the user to the overwrite page (not in the same page) If they want to over write the file. Here are a few option upload the file with a temporary name (ie time of upload) and if exists ask the user to overwrite or rename. The next page will take the file and change it. Give the user the option to overwrite if exists before they upload the file. If they didn't check it and it exists, return an error the file already exists. <SCRIPT LANGUAGE="JavaScript"> var response = confirm('The file "<?=$upload?>" already exists would you like to overwrite?'); if (response) { location.href = "confirm_overwrite.php?ID=SOME_ID_TO_IDENTIFY_THE_FILE"; } // otherwise show the page with a new name </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.