diff --git a/.gitignore b/.gitignore index d4a0307..6aab050 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ i/* +config.php diff --git a/TODO.md b/TODO.md index e2e51ef..58153eb 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ # TODO -- Hash-Funktion durch einen UUID-Generator ersetzen -- maximale Größe der Datei -- Code aufräumen +- create a check for max file size diff --git a/config.php b/config.dist.php similarity index 53% rename from config.php rename to config.dist.php index 8dc9260..ebd9429 100644 --- a/config.php +++ b/config.dist.php @@ -1,15 +1,15 @@ +// Title $title = "imgpaste by gideonstar"; // Displayed text $text = "Click or drop image here..."; -// Writable data directory for images +// Writeable directory for images. Will be created if it does not exist. $datadir = "i"; -// Length of filenames +// Length of the generated file names $length = 8; ?> diff --git a/index.php b/index.php index 06b9212..f377623 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,10 @@ - + diff --git a/script.js b/script.js index ded89f0..5e6c2cc 100644 --- a/script.js +++ b/script.js @@ -1,21 +1,20 @@ dropzone = document.getElementById('dropzone'); -dropzone.addEventListener('dragover', function(e) -{ +dropzone.addEventListener('dragover', function(e) { e.preventDefault(); + this.classList.remove('nodrop'); this.classList.add('drop'); }); -dropzone.addEventListener('dragleave', function(e) -{ +dropzone.addEventListener('dragleave', function(e) { e.preventDefault(); + this.classList.remove('drop'); this.classList.add('nodrop'); }); -dropzone.addEventListener('click', function(e) -{ +dropzone.addEventListener('click', function(e) { e.preventDefault(); input = document.createElement('input'); @@ -24,26 +23,20 @@ dropzone.addEventListener('click', function(e) input.onchange = function(e) { file = e.target.files[0]; - if( - file.type == 'image/png' || - file.type == 'image/jpeg' ) - { + if( file.type == 'image/png' || file.type == 'image/jpeg' ) { upload(e.target.files[0]); } } }); -dropzone.addEventListener('drop', function(e) -{ +dropzone.addEventListener('drop', function(e) { e.preventDefault(); + this.classList.remove('drop'); this.classList.add('nodrop'); file = e.dataTransfer.files[0]; - if( - file.type == 'image/png' || - file.type == 'image/jpeg' ) - { + if( file.type == 'image/png' || file.type == 'image/jpeg' ) { upload(e.dataTransfer.files[0]); } }); @@ -52,12 +45,10 @@ function upload(file) { const data = new FormData(); data.append('upload', file) - fetch('upload.php', - { + fetch('upload.php', { method: 'POST', body: data - }).then(response => - { + }).then(response => { response.json().then(parsedValue => { filename = parsedValue['filename']; datadir = parsedValue['datadir']; diff --git a/upload.php b/upload.php index 7c5018c..9348e6c 100644 --- a/upload.php +++ b/upload.php @@ -1,6 +1,10 @@