Single File Upload
Product Name
Target Language
Supported Styles
Use ctrl + click to select multiple.
Drop Zone
...
//-----------------------------------------------------------------
// Dropzone options
//-----------------------------------------------------------------
//# Prevent Dropzone from auto discovering this element. This is useful
//# when you want to create the Dropzone programmatically later.
//Dropzone.options.myDropzone = false;
//
//# Disable auto discover for all elements:
//Dropzone.autoDiscover = false;
//# "myAwesomeDropzone" is the camelized version of the HTML element's ID
//# Eg: Dropzone.options.myAwesomeDropzone = { ... }
Dropzone.options.dropzone1 = {
url: "upload.php", // Set the target url
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
thumbnailWidth: 80,
thumbnailHeight: 80,
parallelUploads: 20,
dictDefaultMessage: "Drop files here or click to upload",
previewTemplate: previewTemplate,
//previewTemplate: document.querySelector('#preview-template').innerHTML,
//autoQueue: false, // Make sure the files aren't queued until manually added
//previewsContainer: "#previews", // Define the container to display the previews
//clickable: ".fileinput-button", // Define the element that should be used as click trigger to select files.
accept: function(file, done) {
var errMsg = validateTargetFilename(file.name);
if (errMsg.length > 0) {
done(errMsg);
console.log(errMsg);
$("#cmd-status").html(''+errMsg+'');
} else if (file.name.indexOf(" ") > -1) { // check whether filename has spaces
file.name = file.name.replace(" ", "_"); // we get rid of spaces to avoid errors
console.log("File name has spaces: [" + file.name +"]. It needs to be cleaned up.");
//done("Invalid target file name for [" + file.name + "]. \nCannot upload file. \n\nFile name contains spaces.");
done();
$("#cmd-status").html('Success uploading '+file.name+'');
} else {
done();
$("#cmd-status").html('Success uploading '+file.name+'');
}
},
init: function() {
this.on("addedfile", function(file) {
var errMsg = validateTargetFilename(file.name);
if (errMsg.length > 0) {
//alert(errMsg);
//$("#dlg-title").html("File Upload");
//$("#dlg-body").html(errMsg);
//$("#dlg").modal('show');
}
console.log("Added file: targetname [" + file.name + "], " +
"name [" + file.name + "], type [" + file.type + "], size [" + file.size + "]"
);
});
}
};
== Multiple File Upload (Multiple Selection) ==
Multiple File Upload Drop Zone
Files are uploaded as-is. No file renaming. Use responsibly.
...
== Multiple File Upload (Individual Selection) ==
Multiple File Upload (Individual Selection) Drop Zone
...
//-----------------------------------------------------------------
// Programmatically instantiate a Dropzone (dz3)
//-----------------------------------------------------------------
// Get the template HTML and remove it from the doument
var previewNode = document.querySelector("#preview-template");
previewNode.id = "";
var previewTemplate = previewNode.parentNode.innerHTML;
previewNode.parentNode.removeChild(previewNode);
//var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
//var myDropzone = new Dropzone(document.querySelector("#dropzone3"), { // Make the DIV 'form-single-file-upload' a dropzone (using js)
var myDropzone = new Dropzone("#dropzone3", { // Make the DIV 'dropzone3' a dropzone (using jquery)
url: "upload.php", // Set the target url
paramName: "file", // The name that will be used to transfer the file
thumbnailWidth: 80,
thumbnailHeight: 80,
parallelUploads: 20,
previewTemplate: previewTemplate,
autoQueue: false, // Make sure the files aren't queued until manually added
previewsContainer: "#previews", // Define the container to display the previews
clickable: ".fileinput-button" // Define the element that should be used as click trigger to select files.
});
myDropzone.on("addedfile", function(file) {
// Hookup the start button
file.previewElement.querySelector(".start").onclick = function() { myDropzone.enqueueFile(file); };
});
// Update the total progress bar
myDropzone.on("totaluploadprogress", function(progress) {
document.querySelector("#total-progress .progress-bar").style.width = progress + "%";
});
myDropzone.on("sending", function(file) {
// Show the total progress bar when upload starts
document.querySelector("#total-progress").style.opacity = "1";
// And disable the start button
file.previewElement.querySelector(".start").setAttribute("disabled", "disabled");
});
// Hide the total progress bar when nothing is uploading anymore
myDropzone.on("queuecomplete", function(progress) {
document.querySelector("#total-progress").style.opacity = "0";
});
// Setup the buttons for all transfers
// The "add files" button doesn't need to be setup because the config
// `clickable` has already been specified.
document.querySelector("#actions .start").onclick = function() {
myDropzone.enqueueFiles(myDropzone.getFilesWithStatus(Dropzone.ADDED));
};
document.querySelector("#actions .cancel").onclick = function() {
myDropzone.removeAllFiles(true);
};
== Server Side Upload Handling ==