Delete file using a link

后端 未结 5 1319
执笔经年
执笔经年 2021-01-17 01:52

i want to have function like delete file from database by using link instead of button. how can i do that? do i need to use href/unlink or what? Can i do like popup confirma

5条回答
  •  Happy的楠姐
    2021-01-17 02:21

    No links nor buttons can be used for the database interaction. It is server-side code to do such things. You have to understand that your application has 3 layers:

    • an HTML form
    • an server-side code
    • a database

    the first one cannot interact with the last one directly.
    So, on the one hand, it doesn't matter, with link or button you do call your server side code (the code remains the same).
    But, on the other hand, there is a rule:

    use GET method (link) to request information and POST (form/button) to modify it.

    So, you should not use links to remove files, because some too smart bot can wipe all your database in a second.

    As for your question where to place the code, just write a php script, unlink.php which deletes a file by hardcoded path. Then, after you've done that, make this file an action for the HTML form. Hardcoded one. Once you've done that - you can try to generate this form from your database.
    This - step-by-step way - is the only possible way to develop a wab-application

提交回复
热议问题