Dropzone.options.dropzoneFileUpload = { // div has id=dropzoneFileUpload? addRemoveLinks: true, // but still link to delete is not displayed? dictRemoveFile: 'Remove' };
myDropzone.on("complete", function(file) { myDropzone.removeFile(file); // What should I do here? });
.
biên tập:
如果我删除这段代码:
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#my-dropzone", { url: "{{ route('dropzone.upload') }}", headers: { 'X-CSRF-TOKEN': '{!! csrf_token() !!}' } });
public function dropzoneRemove(Request $request) { if($request->ajax()) { $photo = Photo::find($request->photoId); //Get image by id or desired parameters
if(File::exists($destinationPath.$photo->file_name)) //Check if file exists File::delete($destinationPath.$photo->file_name) //Delete file from storage
// myDropzone is the configuration for the element that has an id attribute // with the value my-dropzone (or myDropzone) Dropzone.options.myDropzone = { init: function() { this.on("addedfile", function(file) {
// Create the remove button var removeButton = Dropzone.createElement("");
// Capture the Dropzone instance as closure. var _this = this;
// Listen to the click event removeButton.addEventListener("click", function(e) { // Make sure the button click doesn't submit the form: e.preventDefault(); e.stopPropagation();
// Remove the file preview. _this.removeFile(file); // If you want to the delete the file on the server as well, // you can do the AJAX request here. });
// Add the button to the file preview element. file.previewElement.appendChild(removeButton); }); } };
Dropzone will find all form elements with the class dropzone, automatically attach itself to it, and upload files dropped into it to the specified action attribute. http://www.dropzonejs.com/#usage
Tôi là một lập trình viên xuất sắc, rất giỏi!