2021-08-08 17:23:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$path = __DIR__ . '/../../tmp/quickupload';
|
|
|
|
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
mkdir($path);
|
|
|
|
}
|
|
|
|
$path = realpath($path);
|
|
|
|
|
|
|
|
function slugify($string){
|
|
|
|
return strtolower(trim(preg_replace('/[^.A-Za-z0-9-]+/', '-', $string), '-'));
|
|
|
|
}
|
|
|
|
|
2021-08-08 18:54:01 +00:00
|
|
|
if ($_SERVER['REQUEST_URI'] === '/list') {
|
|
|
|
$files = getFilesAsArray($path);
|
|
|
|
?>
|
|
|
|
<h3>List of uploaded files</h3>
|
|
|
|
<ul>
|
|
|
|
<?php
|
|
|
|
foreach ($files as $fileName) {
|
|
|
|
?>
|
|
|
|
<li><a href="/file/<?= $fileName ?>"><?= $fileName ?></a></li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</ul>
|
|
|
|
<?php
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2021-10-03 14:30:41 +00:00
|
|
|
$file = null;
|
|
|
|
$isAutoGeneratedFileName = false;
|
|
|
|
if (isset($_POST['name']) && !empty($_POST['name'])) {
|
|
|
|
$fileName = $_POST['name'];
|
|
|
|
} else {
|
|
|
|
$fileName = generateRandomString(6);
|
|
|
|
$isAutoGeneratedFileName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['text']) && !empty($_POST['text'])) {
|
|
|
|
if ($isAutoGeneratedFileName) $fileName .= '.txt';
|
|
|
|
file_put_contents($path . '/' . $fileName, $_POST['text']);
|
|
|
|
$file = true;
|
|
|
|
}
|
|
|
|
else if (isset($_FILES['file'])) {
|
|
|
|
$file = $_FILES['file'];
|
|
|
|
if ($isAutoGeneratedFileName) $fileName .= '_' . slugify($file['name']);
|
|
|
|
copy($file['tmp_name'], $path . '/' . $fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file !== null) {
|
2021-08-08 17:23:49 +00:00
|
|
|
?>
|
|
|
|
<div style="padding: 20px; border: 1px solid green; background: green; color: white">
|
2021-10-03 14:30:41 +00:00
|
|
|
File uploaded! <a href="/file/<?= $fileName ?>">Click here to find it</a>
|
2021-08-08 17:23:49 +00:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
2021-10-03 14:30:41 +00:00
|
|
|
|
2021-08-08 17:23:49 +00:00
|
|
|
?>
|
2021-10-03 14:30:41 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>QuickUpload</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>QuickUpload</h1>
|
2021-08-08 17:23:49 +00:00
|
|
|
<form enctype="multipart/form-data" method="POST">
|
2021-10-03 14:30:41 +00:00
|
|
|
Upload a direct file
|
|
|
|
<input type="file" name="file" /><input type="submit" value="Submit">
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
Or paste your data:
|
|
|
|
<textarea name="text" style="margin: 1em 0; width:100%; height: 60vh"></textarea><br>
|
|
|
|
<label for="name">File name:</label>
|
|
|
|
<input type="text" name="name" />
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<input type="submit" value="Submit" style="width: 6em; height: 3em;">
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|