* 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/*
config.php

View File

@ -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

View File

@ -1,15 +1,15 @@
<?php
// Used for <title></title>
// 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;
?>

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>
<html>
<head>

View File

@ -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'];

View File

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