I have a problem with Dropzone.js to delete images after being encrypted and upload with Laravel 5 I have the following code:
$file = $request->file('image');
$extension = $file->getClientOriginalExtension() ?: 'png';
$fileName = $file->getClientOriginalName();
$folderName = '/uploads/images/posts/' . date("Ym", time()) .'/'.date("d", time());
$destinationPath = public_path() . $folderName;
$safeName = md5($fileName).'.'.$extension;
$file->move($destinationPath, $safeName);
Once encrypted and uploaded by ajax with Dropzone if the user makes a mistake or uploads it by mistake or mistake, it should be deleted by the same user before being published.
I put the Dropzone JS code that I use, but that code sends me the original name of the file but not the one encrypted in L5
Dropzone.options.uploadWidget = {
paramName: 'image',
maxFilesize: 10, // MB
maxFiles: 1,
dictDefaultMessage: 'Click para subir una imagen',
previewTemplate: document.querySelector('#preview-template').innerHTML,
previewsContainer: '#dropzonePreview',
addRemoveLinks: true,
dictRemoveFile: 'Remove',
acceptedFiles: 'image/*',
init: function() {
this.on('success', function( file, resp ){
//console.log(resp.url);
$('#file').attr( 'value',resp.name);
});
this.on('thumbnail', function(file) {
if ( file.width < 200 || file.height < 200 ) {
file.rejectDimensions();
} else {
file.acceptDimensions();
}
});
this.on('removedfile', function(file) {
$.ajax({
type: 'POST',
url: site_path + '/post/ajaxdeletefile',
data: {id: file.name},
dataType: 'html',
success: function(data){
// console.log(data);
}
});
});
},
accept: function(file, done) {
file.acceptDimensions = done;
file.rejectDimensions = function() {
done('The image must be at least 640 x 480px')
};
}
};