La til felt for å skrive inn nytt filnavn og valg for å gjør fila privat
This commit is contained in:
parent
aa0a6c2e8c
commit
a9d59af593
87
index.php
87
index.php
@ -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 så 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">
|
||||
<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();
|
||||
}
|
||||
|
18
upload.php
18
upload.php
@ -1,10 +1,8 @@
|
||||
<?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'])) {
|
||||
if(isset($_FILES['file'])) {
|
||||
$file = $_FILES['file'];
|
||||
|
||||
$fileName = $_FILES['file']['name'];
|
||||
@ -15,7 +13,6 @@ error_reporting(E_ALL);
|
||||
$fileError = $_FILES['file']['error'];
|
||||
$_SESSION['filename'] = $fileName;
|
||||
|
||||
$file_destination = 'filer/' . $file_name;
|
||||
|
||||
$fileExt = explode('.', $fileName);
|
||||
$fileActualExt = strtolower(end($fileExt));
|
||||
@ -33,6 +30,17 @@ error_reporting(E_ALL);
|
||||
$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))
|
||||
|
Loading…
Reference in New Issue
Block a user