Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  34] [ 2]  / answers: 1 / hits: 105705  / 11 Years ago, fri, november 1, 2013, 12:00:00

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();
}
}

More From » javascript

 Answers
2

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
}
});
}
}

[#74566] Thursday, October 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
forrestn

Total Points: 552
Total Questions: 94
Total Answers: 101

Location: Sao Tome and Principe
Member since Thu, Apr 20, 2023
1 Year ago
;