Forum Stats

  • 3,872,910 Users
  • 2,266,489 Discussions


Can we delete a text file from server , from javascript method

murali2any1 Member Posts: 20
edited Apr 4, 2016 7:16AM in JavaScript - Nashorn

I have a button in html and onclick on that button.

On clicking the button , i need to insert a file in server project folder and delete the file exisiting.

Note - I will parse the file path and name to the function onclick.

thanks in advance.


KM Krishna.


  • Pedro Curto
    Pedro Curto Member Posts: 39
    edited Apr 4, 2016 7:16AM

    Hello Krishna,

    To delete a file from the server, you need a server-side script, for example create a php file containing the code to delete an file and use ajax to call that php file.


    - For remove a file from the server in php you can use the "unlink" function (see

    - To call a php page using ajax you can use this template:


              url: '<filename>.php',

              data: {'file' : "<path to file you want to delete"},

              success: function (response) {

                 // do something


              error: function () {

                 // do something




    Pedro Curto