php - Replace uploaded document on confirm not working -


my requirement follows: when user uploads file should check "file exists", if file exists must show confirm box if 'ok' have replace , if cancel reverse. following code

if (file_exists($path . $documentname)) {                 $msg = $documentname . " exists. ";                 ?>                 <script type="text/javascript">                     var res = confirm('file exists want replace?');                     if (res == false) {                 <?php                 $msg = 'file upload cancelled';                 ?>                     } else {                   <?php                 if (move_uploaded_file($_files["document"]["tmp_name"], $path . $documentname)) {                     $msg = $documentname . " file replaced successfully";                     $successurl = $document_path . $documentname;                 }                 else                     $msg = $documentname . "upload failed";                 ?>                     }                 </script>";                 <?             } 

my problem if give cancel file getting replaced. let me know i'm wrong or there other approach? please me close issue note:jquery not allowed.

your problem mix javascript , php. php-code run on server , generates html-document. @ point, file gets replaced already.

then, document (with javascript-code inside) send user , there javascript-code run. , in moment, user gets see confirmaion-dialog, though file replaced!

take @ source-code php-code generating , see mean.

a solution add checkbox confirm overwriting files. after hitting upload-/submit-button, php-script check if box checked , either replace file or not.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -