forked from Business/BinStack
Add image uploading for items (close #8)
parent
75d8811477
commit
9a5aefbeb5
Binary file not shown.
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . "/required.php";
|
||||
|
||||
$base = FILE_UPLOAD_PATH . "/";
|
||||
if (isset($_GET['i'])) {
|
||||
$file = $_GET['i'];
|
||||
$filepath = $base . $file;
|
||||
if (!file_exists($filepath) || is_dir($filepath)) {
|
||||
http_response_code(404);
|
||||
die("404 File Not Found");
|
||||
}
|
||||
if (strpos(realpath($filepath), FILE_UPLOAD_PATH) !== 0) {
|
||||
http_response_code(404);
|
||||
die("404 File Not Found");
|
||||
}
|
||||
} else {
|
||||
http_response_code(404);
|
||||
die("404 File Not Found");
|
||||
}
|
||||
|
||||
if (filesize($filepath) > 11) {
|
||||
$imagetype = exif_imagetype($filepath);
|
||||
} else {
|
||||
$imagetype = false;
|
||||
}
|
||||
|
||||
switch ($imagetype) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$mimetype = "image/jpeg";
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$mimetype = "image/gif";
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$mimetype = "image/png";
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$mimetype = "image/webp";
|
||||
break;
|
||||
default:
|
||||
$mimetype = "application/octet-stream";
|
||||
}
|
||||
|
||||
header("Content-Type: $mimetype");
|
||||
header('Content-Length: ' . filesize($filepath));
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
$seconds_to_cache = 60 * 60 * 12; // 12 hours
|
||||
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
|
||||
header("Expires: $ts");
|
||||
header("Pragma: cache");
|
||||
header("Cache-Control: max-age=$seconds_to_cache");
|
||||
|
||||
ob_end_flush();
|
||||
|
||||
readfile($filepath);
|
@ -0,0 +1 @@
|
||||
Deny from all
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"Editing images for item": "Editing images for {item}",
|
||||
"Edit Images": "Edit Images",
|
||||
"Browse": "Browse",
|
||||
"Upload": "Upload",
|
||||
"Promoted": "Promoted",
|
||||
"Promote": "Promote",
|
||||
"Delete": "Delete",
|
||||
"Back": "Back"
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
$images = [];
|
||||
|
||||
if (!empty($VARS['id']) && $database->has('items', ['itemid' => $VARS['id']])) {
|
||||
$images = $database->select('images', ['imageid', 'imagename', 'primary'], ['itemid' => $VARS['id']]);
|
||||
} else {
|
||||
header('Location: app.php?page=items&msg=invalid_itemid');
|
||||
die();
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="card border-green">
|
||||
<h3 class="card-header text-green">
|
||||
<i class="fas fa-images"></i> <?php $Strings->build("Editing images for item", ['item' => "<span id=\"name_title\">" . htmlspecialchars($database->get('items', 'name', ['itemid' => $VARS['id']])) . "</span>"]); ?>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
<div class="ml-auto my-auto">
|
||||
<form action="action.php" method="POST" enctype="multipart/form-data">
|
||||
<div class="input-group">
|
||||
<input type="text" id="uploadstatus" class="form-control" readonly />
|
||||
<div class="input-group-append">
|
||||
<span class="btn btn-primary btn-file">
|
||||
<i class="fas fa-folder-open"></i> <?php $Strings->get("Browse"); ?> <input id="fileupload" type="file" name="files[]" accept=".png,.jpg,.jpeg,.gif,.webp,image/png,image/jpeg,image/gif,image/webp" multiple required />
|
||||
</span>
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-cloud-upload-alt"></i> <?php $Strings->get("Upload"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="action" value="imageupload" />
|
||||
<input type="hidden" name="source" value="editimages" />
|
||||
<input type="hidden" name="itemid" value="<?php echo htmlspecialchars($VARS['id']); ?>" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="row">
|
||||
<?php
|
||||
foreach ($images as $i) {
|
||||
?>
|
||||
<div class="col-12 col-sm-6 col-md-4 col-lg-4 col-xl-3">
|
||||
<div class="card">
|
||||
<img class="card-img" src="image.php?i=<?php echo $i['imagename']; ?>" alt="">
|
||||
<div class="card-img-overlay text-right">
|
||||
<?php
|
||||
if ($i['primary']) {
|
||||
?>
|
||||
<span class="btn btn-green btn-sm" data-toggle="tooltip" data-placement="bottom" title=""><i class="fas fa-check"></i> <?php $Strings->get("Promoted"); ?></span>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<form action="action.php" method="POST">
|
||||
<input type="hidden" name="action" value="promoteimage" />
|
||||
<input type="hidden" name="itemid" value="<?php echo $VARS['id']; ?>" />
|
||||
<input type="hidden" name="imageid" value="<?php echo $i['imageid']; ?>" />
|
||||
<input type="hidden" name="source" value="editimages" />
|
||||
<button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-level-up-alt"></i> <?php $Strings->get("Promote"); ?></button>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<form action="action.php" method="POST">
|
||||
<input type="hidden" name="action" value="deleteimage" />
|
||||
<input type="hidden" name="itemid" value="<?php echo $VARS['id']; ?>" />
|
||||
<input type="hidden" name="imageid" value="<?php echo $i['imageid']; ?>" />
|
||||
<input type="hidden" name="source" value="editimages" />
|
||||
<button type="submit" class="btn btn-danger btn-sm mt-1"><i class="fas fa-trash"></i> <?php $Strings->get("Delete"); ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-footer d-flex">
|
||||
<a href="./app.php?page=edititem&id=<?php echo $_GET['id']; ?>" class="btn btn-success mr-auto"><i class="fas fa-arrow-left"></i> <?php $Strings->get("Back"); ?></a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
.btn-file {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.btn-file input[type=file] {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
min-width: 100%;
|
||||
min-height: 100%;
|
||||
font-size: 100px;
|
||||
text-align: right;
|
||||
filter: alpha(opacity=0);
|
||||
opacity: 0;
|
||||
outline: none;
|
||||
background: white;
|
||||
cursor: inherit;
|
||||
display: block;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
$(document).on('change', ':file', function () {
|
||||
var input = $(this),
|
||||
numFiles = input.get(0).files ? input.get(0).files.length : 1,
|
||||
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
|
||||
input.trigger('fileselect', [numFiles, label]);
|
||||
});
|
||||
|
||||
$(':file').on('fileselect', function (event, numFiles, label) {
|
||||
var message = numFiles > 1 ? numFiles + ' files selected' : label;
|
||||
$("#uploadstatus").val(message);
|
||||
});
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
})
|
Loading…
Reference in New Issue