* config.php nach config.dist.php verschoben

* Code aufgeräumt
This commit is contained in:
root 2023-03-23 10:15:05 +00:00
parent e6fba1ef7b
commit 16ca95dcd3
6 changed files with 31 additions and 28 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
i/* i/*
config.php

View File

@ -1,5 +1,3 @@
# TODO # TODO
- Hash-Funktion durch einen UUID-Generator ersetzen - create a check for max file size
- maximale Größe der Datei
- Code aufräumen

View File

@ -1,15 +1,15 @@
<?php <?php
// Used for <title></title> // Title
$title = "imgpaste by gideonstar"; $title = "imgpaste by gideonstar";
// Displayed text // Displayed text
$text = "Click or drop image here..."; $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"; $datadir = "i";
// Length of filenames // Length of the generated file names
$length = 8; $length = 8;
?> ?>

View File

@ -1,4 +1,10 @@
<?php include('config.php'); ?> <?php
if(is_file('config.php')) {
include('config.php');
} else {
include('config.dist.php');
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>

View File

@ -1,21 +1,20 @@
dropzone = document.getElementById('dropzone'); dropzone = document.getElementById('dropzone');
dropzone.addEventListener('dragover', function(e) dropzone.addEventListener('dragover', function(e) {
{
e.preventDefault(); e.preventDefault();
this.classList.remove('nodrop'); this.classList.remove('nodrop');
this.classList.add('drop'); this.classList.add('drop');
}); });
dropzone.addEventListener('dragleave', function(e) dropzone.addEventListener('dragleave', function(e) {
{
e.preventDefault(); e.preventDefault();
this.classList.remove('drop'); this.classList.remove('drop');
this.classList.add('nodrop'); this.classList.add('nodrop');
}); });
dropzone.addEventListener('click', function(e) dropzone.addEventListener('click', function(e) {
{
e.preventDefault(); e.preventDefault();
input = document.createElement('input'); input = document.createElement('input');
@ -24,26 +23,20 @@ dropzone.addEventListener('click', function(e)
input.onchange = function(e) { input.onchange = function(e) {
file = e.target.files[0]; file = e.target.files[0];
if( if( file.type == 'image/png' || file.type == 'image/jpeg' ) {
file.type == 'image/png' ||
file.type == 'image/jpeg' )
{
upload(e.target.files[0]); upload(e.target.files[0]);
} }
} }
}); });
dropzone.addEventListener('drop', function(e) dropzone.addEventListener('drop', function(e) {
{
e.preventDefault(); e.preventDefault();
this.classList.remove('drop'); this.classList.remove('drop');
this.classList.add('nodrop'); this.classList.add('nodrop');
file = e.dataTransfer.files[0]; file = e.dataTransfer.files[0];
if( if( file.type == 'image/png' || file.type == 'image/jpeg' ) {
file.type == 'image/png' ||
file.type == 'image/jpeg' )
{
upload(e.dataTransfer.files[0]); upload(e.dataTransfer.files[0]);
} }
}); });
@ -52,12 +45,10 @@ function upload(file) {
const data = new FormData(); const data = new FormData();
data.append('upload', file) data.append('upload', file)
fetch('upload.php', fetch('upload.php', {
{
method: 'POST', method: 'POST',
body: data body: data
}).then(response => }).then(response => {
{
response.json().then(parsedValue => { response.json().then(parsedValue => {
filename = parsedValue['filename']; filename = parsedValue['filename'];
datadir = parsedValue['datadir']; datadir = parsedValue['datadir'];

View File

@ -1,6 +1,10 @@
<?php <?php
include('config.php'); if(is_file('config.php')) {
include('config.php');
} else {
include('config.dist.php');
}
if(!is_dir($datadir)) { if(!is_dir($datadir)) {
mkdir($datadir); mkdir($datadir);
@ -8,6 +12,7 @@ if(!is_dir($datadir)) {
if(isset($_FILES['upload'])) { if(isset($_FILES['upload'])) {
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION); $extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') { if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') {
$filename = generate_filename($length) . '.' . $extension; $filename = generate_filename($length) . '.' . $extension;
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename); move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
@ -17,11 +22,13 @@ if(isset($_FILES['upload'])) {
function generate_filename($length) { function generate_filename($length) {
$filename = ""; $filename = "";
for($i = 0; $i < $length; $i++) { for($i = 0; $i < $length; $i++) {
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_char = $chars[rand(0, strlen($chars) - 1)]; $random_char = $chars[rand(0, strlen($chars) - 1)];
$filename = $filename . $random_char; $filename = $filename . $random_char;
} }
return $filename; return $filename;
} }