Filopplasting/upload.php

70 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2023-11-30 23:30:06 +00:00
<?php
session_start();
ini_set('display_errors', '1');
2023-11-30 23:30:06 +00:00
ini_set('display_startup_errors', '1');
2023-12-03 15:16:57 +00:00
2023-12-03 15:51:28 +00:00
$public_url = 'https://filer.trygve.net/';
2023-12-03 15:16:57 +00:00
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;
2023-11-30 23:30:06 +00:00
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
2023-11-30 23:30:06 +00:00
$banned = array('php', 'js', 'php5', 'pht', 'phtml', 'shtml', 'asa', 'cer', 'asax', 'swf');
$allowed = array('zip', 'gz', 'tar', 'png', 'jpg', 'bmp', 'html', 'htm');
2023-11-30 23:30:06 +00:00
foreach ($banned as $url) {
if (strpos($fileActualExt, $url) !== FALSE) {
$fileError = 2;
}
}
2023-11-30 23:30:06 +00:00
if ($file_name === 'index.htm' || $file_name === 'index.html') {
$fileError = 2;
}
2023-11-30 23:30:06 +00:00
if (!empty($_POST['new_filename'])) {
$file_name = $_POST['new_filename'] . '.' .$fileActualExt;
}
2023-11-30 23:30:06 +00:00
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))
2023-11-30 23:30:06 +00:00
{
2023-12-03 15:16:57 +00:00
$path = $public_url . $file_destination;
2023-12-03 15:51:28 +00:00
$filLink = '<a href=" ' . $path . '">' . $path . '</a>';
$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';
2023-11-30 23:30:06 +00:00
}
}
elseif($fileError === 2)
{
$_SESSION['fileupload-response'] = 'banned';
}
else
{
$_SESSION['fileupload-response'] = 'failed';
}
2023-11-30 23:30:06 +00:00
}
2023-12-03 15:53:27 +00:00
header("location:/");
2023-11-30 23:30:06 +00:00
?>