[英]Delete uploaded image using ajax uploader
我使用ajax loader将文件上传到服务器。它工作正常,但现在我想为每个图像设置delete选项,并且可以在保存之前删除该图像。我当前的图像如下所示:
我正在使用此文件上传器脚本进行文件上传。 链接
我的文件上传代码是:
jQuery("#fileuploader").uploadFile({
url:"<?php echo $this->getUrl('pmembers/priority/productimages/') ?>",
multiple:true,
fileName:"myfile",
onSuccess: function (files, response, xhr,pd) {
var dir = '<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."mkd/uploads/".Mage::getSingleton("customer/session")->getId()."/"; ?>';
jQuery('#files').append('<li style="width:60px; float:left;margin-left:5px; margin-right:5px;"><img width="60" height="60" src="'+dir+files+'" /></li><img src="cross.png" />');
},
});
});
尝试:单击“删除”按钮时,事件将发送请求到服务器取消链接(路径:“ dir + files”),完成后服务器将向客户端返回通知。
jQuery的:
var removeButton = $("li > img:last");
removeButton.click(function(){
if (removeButton.attr('handling') != "true") {
removeButton.attr('handling', 'true');
var path = removeButton.prev('img[src]').attr('src');
$.ajax({
type: "POST",
dataType: "json",
url: (url),
data: {'path': path},
error: function () {
//. Action when error.
},
success: function (data) {
//. Action when success.
}
}).done(function(){
removeButton.attr('handling', 'false');
});
}
});
PHP:
$path = $_POST['path'];
$unlink = unlink($path);
if (!$unlink) {
print json_encode(array("return" => false)); exit();
}else {
print json_encode(array("return" => true)); exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.