how do I delete a file using onclick
-
Can anyone tell me how to delete a file with onclick? I thought I could use the following code, but it turns out that the file was deleted upon every page load regardless of whether the reset button was clicked.
<?php $triggerfile = "wp-content/themes/headway-208/ideas.docx"; if (file_exists($triggerfile)) { echo '<input type="button" value="Reset" onClick="'.unlink($triggerfile).'">'; } else { echo "The file $triggerfile does not need to be reset"; } ?>
I’ve been told I need to use Ajax, although I’m not familiar with Ajax at all. I did find this thread which might steer me in the right direction.
https://www.phpfreaks.com/forums/index.php?topic=159544.0
However, given that this is all located on a wordpress page, I’m not sure how to implement everything. Specifically, where does the ajax.php go?I may be going about this wrong. If so, please somebody turn me in the right direction or direct me to some documentation or code that would be helpful.
Thanks much!
- The topic ‘how do I delete a file using onclick’ is closed to new replies.