Forum Stats

  • 3,726,962 Users
  • 2,245,299 Discussions
  • 7,852,512 Comments

Discussions

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

murali2any1
murali2any1 Member Posts: 20
edited April 2016 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.

yours,

KM Krishna.

Answers

  • Pedro Curto
    Pedro Curto Member Posts: 39
    edited April 2016

    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

Sign In or Register to comment.