82 lines
1.8 KiB
PHP
82 lines
1.8 KiB
PHP
<?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), '-'));
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
$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) {
|
|
?>
|
|
<div style="padding: 20px; border: 1px solid green; background: green; color: white">
|
|
File uploaded! <a href="/file/<?= $fileName ?>">Click here to find it</a>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>QuickUpload</title>
|
|
</head>
|
|
<body>
|
|
<h1>QuickUpload</h1>
|
|
<form enctype="multipart/form-data" method="POST">
|
|
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>
|