This commit is contained in:
root 2023-03-22 22:10:33 +00:00
commit 28cdf2d54a
8 changed files with 167 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
i/*

15
config.php Normal file
View File

@ -0,0 +1,15 @@
<?php
// Used for <title></title>
$title = "imgpaste by gideonstar";
// Displayed text
$text = "Drop image here...";
// Writable data directory for images
$datadir = "i";
// Length of filenames
$hashlen = 8;
?>

18
index.php Normal file
View File

@ -0,0 +1,18 @@
<?php include('config.php'); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title; ?></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="wrapper">
<div id="dropzone" class="nodrop">
<p><?php echo $text; ?></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

2
robots.txt Normal file
View File

@ -0,0 +1,2 @@
User-agent: *
Disallow: /

61
script.js Normal file
View File

@ -0,0 +1,61 @@
dropzone = document.getElementById('dropzone');
dropzone.addEventListener('dragover', function(e)
{
e.preventDefault();
this.classList.remove('nodrop');
this.classList.add('drop');
});
dropzone.addEventListener('dragleave', function(e)
{
e.preventDefault();
this.classList.remove('drop');
this.classList.add('nodrop');
});
/*dropzone.addEventListener('click', function(e)
{
e.preventDefault();
input = document.createElement('input');
input.type = 'file';
input.click();
});*/
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' )
{
upload(e.dataTransfer.files[0]);
}
});
function upload(file) {
const data = new FormData();
data.append('upload', file)
fetch('upload.php',
{
method: 'POST',
body: data
}).then(response =>
{
response.json().then(parsedValue => {
filename = parsedValue['filename'];
datadir = parsedValue['datadir'];
openUploadedFile(datadir, filename);
})
});
};
function openUploadedFile(datadir, filename) {
window.open(window.location.href + datadir + '/' + filename, '_self');
};

BIN
sora.ttf Normal file

Binary file not shown.

47
style.css Normal file
View File

@ -0,0 +1,47 @@
:root {
--round: 20px;
--border: 100px;
}
@font-face {
font-family: 'Sora';
src: url('sora.ttf');
}
* {
margin: 0;
padding: 0;
}
body {
background-color: #101010;
font-family: 'Sora';
font-size: 14px;
}
#wrapper {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
#dropzone {
width: calc(100vw - var(--border));
height: calc(100vh - var(--border));
border-radius: var(--round);
display: flex;
align-items: center;
justify-content: center;
}
.nodrop {
background-color: #f5f5f5;
outline: 2px dashed #d5d5d5;
}
.drop {
background-color: #ffb703;
outline: 2px dashed #fb8500;
}

23
upload.php Normal file
View File

@ -0,0 +1,23 @@
<?php
include('config.php');
if(isset($_FILES['upload'])) {
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
$filename = generate_hash($hashlen) . '.' . $extension;
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
}
function generate_hash(int $length) {
$hash = "";
for($i = 0; $i < $length; $i++) {
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_char = $chars[rand(0, strlen($chars) - 1)];
$hash = $hash . $random_char;
}
return $hash;
}
?>