1

I have this line for delete a folder

<button class='elimina' data-elimina='$path/$file'>elimina $path/$file</button>

get the folder path via JQuery

 $(".elimina").click(function(){
     var data = $(this).data('elimina');
     $.post('file.php',data, function(response) {
        // Log the response to the console
        console.log("Response: "+response);
        });
      });

At the last I pass it to my file.php

$archivo = $_POST['data'];

    rmdir($archivo);

But never got pass the var data to my php file .I put an if(isset($_POST['data'])){echo $_POST['data'];} and never saw the path,but I now the path arrive to Jquery script (because also tested).

I haven´t form,only the button,could be it the problem?

2
  • 1
    that code is extraordinarily dangerous. you're allowing ANYONE to delete ANY file server for which they know the path and your webserver userID has the rights to. Commented Jun 22, 2016 at 20:16
  • Is only for my work,I hope anybody will try nothing dangerous Commented Jun 22, 2016 at 21:05

1 Answer 1

1

This is wrong:

 $.post('file.php',data, function(response) {
                    ^^^^

You're not sending a key:value pair, you're just sending value. With no key, PHP has nothing to use to produce a $_POST entry

You should have

 $.post('file.php',{data:data}, function(response) {
                    ^-key  ^--value
Sign up to request clarification or add additional context in comments.

7 Comments

I did it,but I still have the same issue,any folder is delete,and I have any echo (I changed it for test)
@Ini This should have solved the problem, there must be something else you're not showing us. What does var_dump($_POST) show?
@ini Are you using an absolute path for the directory?
@ini Is the directory empty? rmdir() will only delete an empty directory. If it's not empty, you have to delete everything in it first, and recurse into subdirectories as well.
rmdir returns boolean false on failure. you should be returning that as well, e.g something as simple as if(rmdir(...)) { echo 'success'; } else { echo 'failure'; }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.