如何使用javascript从文件夹中删除文件? [英] How to delete file from folder using javascript?
本文介绍了如何使用javascript从文件夹中删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用javascript从文件夹中删除文件..?这是我的功能
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..
您实际上可以使用ajax并调用服务器端文件来执行此操作,例如
You can actually use ajax and call a server-side file to do that for e.g.
创建一个文件delete.php
Make a file delete.php
<?php
unlink($_GET['file']);
?>
和javascript
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
}
});
}
}
这篇关于如何使用javascript从文件夹中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文