How to delete a file with javascript?

前端 未结 7 1148
栀梦
栀梦 2020-12-18 06:54

Did not have luck with these examples:
Javascript File remove
Javascript FSO DeleteFile Method
Deleting a File

There are no special permissions on the fi

7条回答
  •  时光取名叫无心
    2020-12-18 07:42

    You can't delete files over HTTP (well in theory you can, but it's not implemented.)

    The easiest way is to set up a tiny server side script (e.g. in ASP or PHP) and to call that from JavaScript. The server side script needs the proper permissions to do the deletion, but otherwise there is no problem.

    In PHP the start would look like this: (Not expanding solution to a fully secure one because you're not saying what platform you are on)

    
    

    you would call the script like this:

    http://yourserver/directory/delete_file.php?file=directory/filename
    

提交回复
热议问题