Callback from a file delete ?
Hi, Is there any callback from this page https://github.com/blueimp/jQuery-File-Upload/wiki/Options that is triggered whenever a file is deleted ?
I´m trying to remove a file from a database when a file delete occurs.
Thanks
Ok, I found something :
First you edit the Javascript Template to add an hidden field with the filename:
<script id="template-download" type="text/x-jquery-tmpl">
<tr class="template-download{{if error}} ui-state-error{{/if}}">
{{if error}}
...
{{else}}
...
<td class="name">
<a href="${url}"{{if thumbnail_url}} target="_blank"{{/if}}>${name}</a>
** <input type="hidden" name="file_name" value="${name}" /> **
</td>
...
{{/if}}
...
</tr>
</script>
now in the file jquery.fileupload-ui.js in the destroy callback :
destroy: function (e, data) {
var that = $(this).data('fileupload');
/** Get the filename **/
var fileName = $("input[name='file_name']", data.context).val();
if (data.url) {
$.ajax(data)
.success(function () {
that._adjustMaxNumberOfFiles(1);
$(this).fadeOut(function () {
$(this).remove();
});
//--> Delete the file ine he database with the new var fileName
});
} else {
data.context.fadeOut(function () {
$(this).remove();
});
}
}
If you're doing a multiple upload you can use this code for the hidden field :
<input type="hidden" name="file_name[]" value="${name}" />
now in your $_POST['file_name'] you will have an array.
Hope it can help you and sorry for my english :)
Kaimite
Thanks !!! I will try this and give some feedback :)
Thanks !! it worked very well, and give some ideas to future workarounds. excellent work :)
You're welcome :)
There is another option:
$('#fileupload').bind('fileuploaddestroy', function (e, data) {
// YOUR CODE
});
Regards
Thank's :) I'll try this.
See You, Kaimite
@isaacsf
Thanks, it worked. Couldn't find documentation on it...so I appreciate you listing this binding here.
Up! How can I get the name of the deleted file with bind('fileuploaddestroy', function (e, data) ?
@Sispheor
Try this...
$('#fileupload').bind('fileuploaddestroy', function (e, data) {
var filename = data.url.substring(data.url.indexOf("=") + 1);
});
It work well thanks JeffJohnson !!