1 Reply Latest reply on Apr 4, 2016 11:16 AM by Pedro Curto

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

    murali2any1

      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.

       

      yours,

      KM Krishna.

        • 1. Re: Can we delete a text file from server , from javascript method
          Pedro Curto

          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.

           

          Tips:

          - For remove a file from the server in php you can use the "unlink" function (see http://www.w3schools.com/php/func_filesystem_unlink.asp)

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

           

                  $.ajax({

                    url: '<filename>.php',

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

                    success: function (response) {

                       // do something

                    },

                    error: function () {

                       // do something

                    }

                  });

           

          Regards,

          Pedro Curto