Added filopplasting.

This commit is contained in:
Trygve 2021-03-16 21:48:33 +01:00
parent 71cf153672
commit a4e67b9434
2 changed files with 137 additions and 0 deletions

72
filopplasting/index.php Executable file
View File

@ -0,0 +1,72 @@
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="no">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="UTF-8">
<meta name="theme-color" content="#263238"/>
<link rel="icon" type="image/png" href="/dist/favicon.png">
<link rel="stylesheet" href="../common/main.css">
<style media="screen">
#upload_button
{
display: inline-block;
}
#upload_button input[type=file] {
display:none;
}
#center{
margin: 0 auto;
}
</style>
<script>
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
</script>
</head>
<body class="theme-auto">
<?php include "../common/header.html"; ?>
<body>
<center>
<div class="cont">
<h1>Filopplasting</h1>
<p>
Her kan du laste opp filer for å dele med andre. Filene kan være maks 5GB.<br /> Serveren ligger i Kristiansand og har 500/500 internet <br />
All opplasting skjer eget ansvar.
</p>
<div>
<a class="btn btn-info" href="http://trygve.me/filopplasting/alle-filer/">Se alle filer</a>
</div>
<hr class="my-4">
<div>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />
<input type="file" name="file" class="" >
<button type="submit" class="btn btn-raised btn-primary">Last opp </button>
</div>
</form>
</div>
</ul>
</div>
</center>
</body>
</html>

65
filopplasting/upload.php Executable file
View File

@ -0,0 +1,65 @@
<?php
session_start();
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
if(isset($_FILES['file'])) {
$file = $_FILES['file'];
//file properties
$fileName = $_FILES['file']['name'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$fileError = $_FILES['file']['error'];
$fileNewName = $fileName;
$file_destination = 'filer/' . $file_name;
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$banned = array('php', 'js', 'html', 'htm', 'php5', 'pht', 'phtml', 'shtml', 'asa', 'cer', 'asax', 'swf');
$allowed = array('zip', 'gz', 'tar', 'png', 'jpg', 'bmp');
//if(in_array($fileActualExt, $banned))
//{
//$fileError = 2;
//}
foreach ($banned as $url) {
if (strpos($fileActualExt, $url) !== FALSE) {
$fileError = 2;
}
}
// require "fileLogger.php";
if($fileError == 0)
{
if(move_uploaded_file($file_tmp, $file_destination))
{
$path = 'https://trygve.me/filopplasting/' . $file_destination;
$filLink = '<a href=" ' . $path . '" class="alert-link">' . $path . '</a>';
//echo $fillink;()
$buttonData = 'Filen ble lastet opp! <a href="' . $filLink . '" class="btn btn-info">Kopier lenke</a>';
$_SESSION['linkData'] = 'Filen ble lastet opp! ' . $filLink;
$_SESSION['link'] = $path;
$_SESSION['fileupload-response'] = 'success';
}
}
elseif($fileError === 2)
{
$_SESSION['fileupload-response'] = 'banned';
}
else
{
$_SESSION['fileupload-response'] = 'failed';
}
}
header("location:../filopplasting");
?>