Improve uploading significantly
This commit is contained in:
parent
4735ac997c
commit
0c87171b50
|
@ -1,5 +1,6 @@
|
|||
[html]
|
||||
instance_name = curload
|
||||
instance_description = curload is a simple file uploading site allowing users to upload files by authenticating using a key.
|
||||
css = index.css
|
||||
javascript = index.js
|
||||
logo = logo.svg
|
||||
|
|
|
@ -23,6 +23,7 @@ $replaceOriginal = false;
|
|||
$logoHeaderSize = 16;
|
||||
$dateFormat = "Y/m/d";
|
||||
$instanceName = "curload";
|
||||
$instanceDescription = "curload is a simple file uploading site allowing users to upload files by authenticating using a key.";
|
||||
$cookieName = "speedierocks";
|
||||
$enableKeys = true;
|
||||
$enableAdminKeys = true;
|
||||
|
@ -50,6 +51,7 @@ $storeUploads = $configEntries['store_number_of_uploads'];
|
|||
$logoHeaderSize = $configEntries['logo_header_size'];
|
||||
$dateFormat = $configEntries['date_format'];
|
||||
$instanceName = $configEntries['instance_name'];
|
||||
$instanceDescription = $configEntries['instance_description'];
|
||||
$publicUploading = $configEntries['public_uploading'];
|
||||
$renameDuplicates = $configEntries['rename_duplicates'];
|
||||
$replaceOriginal = $configEntries['replace_original'];
|
||||
|
|
15
core.php
15
core.php
|
@ -10,7 +10,7 @@ function printHeader($html) {
|
|||
$html .= "<!DOCTYPE html>\n";
|
||||
$html .= "<html>\n";
|
||||
$html .= "\t<head>\n";
|
||||
$html .= "\t\t<meta name=\"description\" content=\"$instanceName is a simple file uploading site allowing users to upload files by authenticating using a key.\">\n";
|
||||
$html .= "\t\t<meta name=\"description\" content=\"$instanceDescription\">\n";
|
||||
$html .= "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
||||
|
||||
if (file_exists($Icon)) $html .= "\t\t<link rel=\"icon\" href=\"$Icon\" />\n";
|
||||
|
@ -21,7 +21,18 @@ function printHeader($html) {
|
|||
$html .= "\t\t<div class=\"bar\">\n";
|
||||
$html .= "\t\t\t<span id='titleSpan' class='title'>\n";
|
||||
if (file_exists($Logo)) $html .= "\t\t\t\t<img src=\"$Logo\" id=\"titleLogo\" class=\"title\" width=\"$logoHeaderSize\" height=\"$logoHeaderSize\">\n";
|
||||
$html .= "\t\t\t\t$instanceName\n";
|
||||
$html .= "\t\t\t\t<small id='title'><a id='title' href=\"/\">$instanceName</a></small>\n";
|
||||
|
||||
if (!isset($_COOKIE[$cookieName])) {
|
||||
$html .= "\t\t\t\t<small id='login'><a href=\"login.php\">Log in</a></small>\n";
|
||||
} else {
|
||||
$html .= "\t\t\t\t<small id='logout'><a href=\"login.php?logout=true\">Log out</a></small>\n";
|
||||
}
|
||||
|
||||
if (isset($_COOKIE[$cookieTypeName]) && $_COOKIE[$cookieTypeName] == 2) {
|
||||
$html .= "\t\t\t\t<small id='administration'><a id='administration' href=\"admin.php\">Administration</a></small>\n";
|
||||
}
|
||||
|
||||
$html .= "\t\t\t</span>\n";
|
||||
$html .= "\t\t</div>\n";
|
||||
$html .= "\t</head>\n";
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
#title {
|
||||
color: #f0eee4;
|
||||
}
|
||||
|
||||
#administration {
|
||||
color: #ffc0cb;
|
||||
}
|
||||
|
||||
.bar img {
|
||||
float: left;
|
||||
padding-right: 5px;
|
||||
|
|
29
index.php
29
index.php
|
@ -8,12 +8,37 @@ function main() {
|
|||
include "config.php";
|
||||
include "core.php";
|
||||
|
||||
$Error = "";
|
||||
$html = "";
|
||||
|
||||
$html = printHeader($html);
|
||||
|
||||
$html .= "\t\t\t<h1>speedie's super awesome file uploader junk</h1>\n";
|
||||
$html .= "\t\t\t<form action=\"upload.php\" method=\"post\" enctype=\"multipart/form-data\">Select file to upload<br><input type=\"file\" name=\"file\" id=\"file\"><br><input type=\"text\" name=\"key\" placeholder=\"Upload key here\"><br><input type=\"submit\" value=\"Upload selected file\" name=\"web\"></form>\n";
|
||||
$html .= "\t\t\t<h1>$instanceName</h1>\n";
|
||||
$html .= "\t\t\t\t<p>$instanceDescription</h1>\n";
|
||||
|
||||
if (isset($_REQUEST['e'])) {
|
||||
$Error = $_REQUEST['e'];
|
||||
}
|
||||
|
||||
if (isset($_COOKIE[$cookieTypeName])) {
|
||||
$html .= "\t\t\t<form action=\"upload.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
|
||||
$html .= "\t\t\t\t<input type=\"file\" name=\"file\" id=\"file\">\n";
|
||||
$html .= "\t\t\t\t<input type=\"submit\" value=\"Upload selected file\" name=\"web\">\n";
|
||||
$html .= "\t\t\t</form>\n";
|
||||
$html .= "\t\t\t<p>Max file size: $maxFileSize MB</p>\n";
|
||||
|
||||
// error handling
|
||||
if ($Error == "file") {
|
||||
$html .= "\t\t\t<p class=\"error\">No file specified.</p>\n";
|
||||
} else if ($Error == "size") {
|
||||
$html .= "\t\t\t<p class=\"error\">File is too big.</p>\n";
|
||||
} else if ($Error == "key") {
|
||||
$html .= "\t\t\t<p class=\"error\">Invalid key. WTF?</p>\n";
|
||||
} else if ($Error == "wtf") {
|
||||
$html .= "\t\t\t<p class=\"error\">WTF? Try again.</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$html .= "\t\t\t<a href=\"https://git.speedie.site/speedie/curload\">source code</a>\n";
|
||||
|
||||
$html = printFooter($html);
|
||||
|
|
46
upload.php
46
upload.php
|
@ -7,8 +7,14 @@
|
|||
include "config.php";
|
||||
include "create-table.php";
|
||||
|
||||
$WebInterface = 1;
|
||||
|
||||
if (isset($_REQUEST['key'])) {
|
||||
$Key = $_REQUEST['key'];
|
||||
$WebInterface = 0;
|
||||
} else if (isset($_COOKIE[$cookieName])) {
|
||||
$Key = $_COOKIE[$cookieName];
|
||||
$WebInterface = 1;
|
||||
} else {
|
||||
print "No key specified.";
|
||||
die();
|
||||
|
@ -22,8 +28,13 @@ $keyID = 0;
|
|||
$self = dirname($_SERVER['PHP_SELF']);
|
||||
|
||||
if (!isset($_FILES['file']['name'])) {
|
||||
if ($WebInterface == 0) {
|
||||
print "You didn't specify a file.";
|
||||
die();
|
||||
} else {
|
||||
header("Location: /?e=file");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
// init database
|
||||
|
@ -153,14 +164,24 @@ if (!$publicUploading || $publicUploading == "false") {
|
|||
|
||||
// Not an authorized key
|
||||
if ($Authorized == 0) {
|
||||
print "Not authorized: Key '$Key' is invalid.";
|
||||
if ($WebInterface == 0) {
|
||||
print "Not authorized: Your key is invalid.";
|
||||
die();
|
||||
} else {
|
||||
header("Location: /?e=key");
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($_FILES['file']['size'] > $uploadLimit && $uploadLimit > 0) {
|
||||
if ($WebInterface == 0) {
|
||||
print "File is too big. Max file size is $maxFileSize" . "MB";
|
||||
die();
|
||||
} else {
|
||||
header("Location: /?e=size");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
// check if file is too big to be uploaded
|
||||
|
@ -183,8 +204,13 @@ if (!$replaceOriginal || $replaceOriginal == "false") {
|
|||
}
|
||||
|
||||
if (file_exists($destinationFile)) { // wtf
|
||||
print "Failed to upload file.";
|
||||
if ($WebInterface == 0) {
|
||||
print "Upload failed.";
|
||||
die();
|
||||
} else {
|
||||
header("Location: /?e=wtf");
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,15 +222,25 @@ if (move_uploaded_file($_FILES['file']['tmp_name'], $destinationFile)) {
|
|||
$DatabaseQuery = $Database->query('SELECT * FROM uploads');
|
||||
$Database->exec("INSERT INTO uploads(file, uploaddate, keyid, keytype) VALUES('$uploadedFile', '$lastUsed', '$keyID', '$keyType')");
|
||||
|
||||
if ($WebInterface == 0) {
|
||||
print "$uploadedFile";
|
||||
} else {
|
||||
header("Location: $uploadedFile");
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['web'])) { // redirect back to index
|
||||
print "<p><a href=\"$uploadedFile\">Your link</a></p>\n";
|
||||
header("Redirect: $uploadedFile");
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
print "Failed to upload file.";
|
||||
print $_FILES['file']['error'];
|
||||
if (file_exists($destinationFile)) { // wtf
|
||||
if ($WebInterface == 0) {
|
||||
print "Upload failed.";
|
||||
die();
|
||||
} else {
|
||||
header("Location: /?e=wtf");
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue