Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Drag and Drop Documents</title>
- <style>
- #drop_zone {
- width: 100%;
- height: 200px;
- border: 2px dashed #aaa;
- text-align: center;
- line-height: 200px;
- margin-bottom: 20px;
- }
- #drop_zone.hover {
- background-color: #f0f0f0;
- }
- </style>
- </head>
- <body>
- <div id="drop_zone">
- <p>Drag and drop documents here</p>
- </div>
- <input type="file" id="file_input" style="display: none;">
- <button onclick="document.getElementById('file_input').click();">Browse</button>
- <script>
- window.onload = function() {
- var dropZone = document.getElementById('drop_zone');
- dropZone.ondragover = function(e) {
- e.preventDefault();
- this.className = 'hover';
- };
- dropZone.ondragleave = function() {
- this.className = '';
- };
- dropZone.ondrop = function(e) {
- e.preventDefault();
- this.className = '';
- var files = e.dataTransfer.files;
- uploadFiles(files);
- };
- document.getElementById('file_input').onchange = function(e) {
- var files = e.target.files;
- uploadFiles(files);
- };
- function uploadFiles(files) {
- var formData = new FormData();
- for (var i = 0; i < files.length; i++) {
- formData.append('file', files[i]);
- }
- var xhr = new XMLHttpRequest();
- xhr.open('POST', '/upload');
- xhr.onload = function() {
- if (xhr.status === 200) {
- console.log('Files uploaded successfully');
- } else {
- console.error('Error uploading files: ', xhr.statusText);
- }
- };
- xhr.send(formData);
- }
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement