Is there any way to delete files from folder using javascript..? Here is my function
function deleteImage(file_name)
{
var r = confirm("Are you sure you want to delete this Image?")
if(r == true)
{
var file_path = <?php echo dirname(__FILE__) . '/uploads/'?>+file_name;
file_path.remove();
}
}
You cannot delete anything without any server-side script..
You can actually use ajax and call a server-side file to do that for e.g.
Make a file delete.php
<?php
unlink($_GET['file']);
?>
and in the javascript
function deleteImage(file_name)
{
var r = confirm("Are you sure you want to delete this Image?")
if(r == true)
{
$.ajax({
url: 'delete.php',
data: {'file' : "<?php echo dirname(__FILE__) . '/uploads/'?>" + file_name },
success: function (response) {
// do something
},
error: function () {
// do something
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With