0

My script is not working.

"sb-pdfs/" is the path where the file is located that I want to delete. If I substitute the $_GET part with the correct file name and call the php scripts directly, then the file is in fact deleted, but not when I try to do it with the Ajax function. I could also just substitute the php with a simple echo which is not called either.

<?php 

unlink ('sb-pdfs/'+($_GET['file']));
   
?>

So the error seems to be on the AJAX side:

  function loeschen(clicked_id)
  {
      alert(clicked_id);
        
      $.ajax({
          url: 'unlink.php',
          data: {'file' : clicked_id },
          success: function (response) {
             if( response.status === true ) {
                 alert('File Deleted!');
             }
             else alert('Did not work!');
          }
        });

    }

I get the correct clicked_id alert, but also the "Did not work!" alert and the file is not deleted.

Edit: clicked_id is the filename of the file I want to delete.

Coffeehouse
  • 505
  • 1
  • 3
  • 15

1 Answers1

2

Your string concatenation is incorrect, you need to use dots . in PHP


unlink ('sb-pdfs/' . ($_GET['file']));
   
?>

As other users have pointed it out, it would be a big security issue as it stands, I would advise a lot of parsing or using an ID system instead of filenames

Victor bvn
  • 167
  • 7