La til felt for å skrive inn nytt filnavn og valg for å gjør fila privat

This commit is contained in:
Trygve 2023-12-03 16:03:39 +01:00
parent aa0a6c2e8c
commit a9d59af593
2 changed files with 103 additions and 84 deletions

View File

@ -27,8 +27,16 @@ session_start();
height: 100vh;
background: url('img/sand.bmp');
}
form {
margin-top: 1rem;
}
.center {
margin: auto;
margin-top: 2rem;
margin-bottom: 2rem;
}
.main{
width: 100%;
}
input::file-selector-button {
font-family: "Pixelated MS Sans Serif",Arial;
@ -56,10 +64,15 @@ session_start();
outline-offset: -4px;
box-shadow: inset -1px 1px #cee7ff,inset 1px 2px #98b8ea,inset -2px 2px #bcd4f6,inset 1px -1px #89ade4,inset 2px -2px #89ade4;
}
@media screen and (min-width: 600px) {
.main{
width: 600px;
}
}
</style>
</head>
<body>
<div class="window center" style="width: 800px">
<div class="window center main">
<div class="title-bar">
<div class="title-bar-text">Trygves filopplasting!</div>
<div class="title-bar-controls">
@ -67,49 +80,47 @@ session_start();
</div>
</div>
<div class="window-body">
<p>Hei! Her kan du laste opp filer du ønsker å dele med andre, eller bare deg selv. Fra tid til annen sletter jeg filene her for for å spare plass denne sida er kun for midlertidig fillagring.</p>
<a href="filer.trygve.net/offentlig">Her kan du bla gjennom alle offentlige filer</a>
<article>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="checkbox" id="privat">
<label for="privat">Privat opplasting</label><br>
<input type="file" name="file">
<button type="submit">Last opp </button>
<div class="field-row">
<label for="file">Velg fil</label>
<input type="file" name="file" id="file">
</div>
<div class="field-row">
<label for="name">Gi fila et nytt navn:</label>
<input name="new_filename" type="text" />
</div>
<div class="field-row">
<input type="checkbox" name="public" id="public_check">
<label for="public_check">Gjør fila søkbar</label>
<button type="submit">Last opp </button>
</div>
</div>
</form>
</div>
</div>
<?php
function popup($title, $message, $icon_name) {
return '<div class="window center" style="width: 300px" id="popup">
<div class="title-bar">
<div class="title-bar-text">' . $title . '</div>
<div class="title-bar-controls">
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
<p>'. $message . '</p>
<section class="field-row" style="justify-content: flex-end"><button onclick="document.getElementById(\'popup\').remove()">Ok</button></section>
</div>
</div>';
}
if(isset($_SESSION['fileupload-response'])) {
$errorMSG = '
<div class="window" style="width: 300px">
<div class="title-bar">
<div class="title-bar-text">' .$_SESSION['filename'] . '</div>
<div class="title-bar-controls">
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
Hmmmm... Her var det visst noe som gikk galt.
<button>Ok</button>
</div>
</div>';
$bannedMSG = '
<div class="window" style="width: 300px">
<div class="title-bar">
<div class="title-bar-text">' . $_SESSION['filename'] . '</div>
<div class="title-bar-controls">
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
Denne filtypen er forbudt!
<button>Ok</button>
</div>
</div>';
if($_SESSION['fileupload-response'] == "success") {
$successMSG = '
<div class="window" style="width: 300px">
<div class="window center" style="width: 300px">
<div class="title-bar">
<div class="title-bar-text">' . $_SESSION['filename'] . '</div>
<div class="title-bar-controls">
@ -117,10 +128,10 @@ session_start();
</div>
</div>
<div class="window-body">
'
<p>'
. $_SESSION['linkData'] .
'
<button type="button" class="btn btn-primary" onclick="copyToClipboard(\'' . $_SESSION['link'] . '\')">Kopier lenke</button>
'</p>
<section class="field-row" style="justify-content: flex-end"><button onclick="copyToClipboard(\'' . $_SESSION['link'] . '\')">Kopier lenke</button></section>
</div>
</div>
';
@ -128,10 +139,10 @@ session_start();
echo($successMSG);
}
elseif ($_SESSION['fileupload-response'] == "failed") {
echo($errorMSG);
echo(popup($_SESSION['filename'], 'Oisan, noe gikk vist galt!', 'ERROR'));
}
elseif ($_SESSION['fileupload-response'] == "banned") {
echo($bannedMSG);
echo(popup($_SESSION['filename'], 'Stoppe en hall! Denne filtypen er forbudt!', 'ERROR'));
}
session_destroy();
}

View File

@ -1,59 +1,67 @@
<?php
session_start();
ini_set('display_errors', '1');
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
if(isset($_FILES['file'])) {
$file = $_FILES['file'];
if(isset($_FILES['file'])) {
$file = $_FILES['file'];
$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'];
$_SESSION['filename'] = $fileName;
$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'];
$_SESSION['filename'] = $fileName;
$file_destination = 'filer/' . $file_name;
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$banned = array('php', 'js', 'php5', 'pht', 'phtml', 'shtml', 'asa', 'cer', 'asax', 'swf');
$allowed = array('zip', 'gz', 'tar', 'png', 'jpg', 'bmp', 'html', 'htm');
$banned = array('php', 'js', 'php5', 'pht', 'phtml', 'shtml', 'asa', 'cer', 'asax', 'swf');
$allowed = array('zip', 'gz', 'tar', 'png', 'jpg', 'bmp', 'html', 'htm');
foreach ($banned as $url) {
if (strpos($fileActualExt, $url) !== FALSE) {
$fileError = 2;
}
}
if ($file_name === 'index.htm' || $file_name === 'index.html') {
$fileError = 2;
}
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';
foreach ($banned as $url) {
if (strpos($fileActualExt, $url) !== FALSE) {
$fileError = 2;
}
}
elseif($fileError === 2)
}
if ($file_name === 'index.htm' || $file_name === 'index.html') {
$fileError = 2;
}
if (!empty($_POST['new_filename'])) {
$file_name = $_POST['new_filename'] . '.' .$fileActualExt;
}
if ($_POST['public'] == True) {
$file_destination = 'offentlig/' . $file_name;
}
else {
$file_destination = 'privat/' . $file_name;
}
if($fileError == 0)
{
if(move_uploaded_file($file_tmp, $file_destination))
{
$_SESSION['fileupload-response'] = 'banned';
}
else
{
$_SESSION['fileupload-response'] = 'failed';
$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");