// Arrastar
$('.upload-content').on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Solte aqui");
});
// Arrastar :hover
$('.upload-content').on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Solte aqui");
});
// Soltar
$('.upload-content').on('drop', function (e) {
e.stopPropagation();
e.preventDefault();
$(".upload-content-title").text("Carregando...");
var fd = new FormData();
var file = e.originalEvent.dataTransfer.files;
fd.append('file', file[0]);
upload(fd);
});
// Abrir arquivo seletor quando clicar na div
$("#uploadfile").on('click', function () {
$("#file").click();
});
// Arquivo selecionado
$("#file").change(function () {
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file', files);
upload(fd);
});
function upload(formData) {
$.ajax({
url: "upload.php",
type: "POST",
data: formData,
contentType: false,
processData: false,
dataType: 'json',
success: response => {
console.log(response);
$(".upload-content-title").text("Solte o arquivo aqui ou clique para selecionar o mesmo");
}
});
}
-
Notifications
You must be signed in to change notification settings - Fork 0
Drag and drop file uploads with jQuery and AJAX
License
DevCia/Drag-drop-file-upload-jquery-ajax
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Drag and drop file uploads with jQuery and AJAX
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published