photoprismupload/index.php

72 lines
2.3 KiB
PHP
Raw Normal View History

2021-08-24 17:59:30 +00:00
<?php
session_start();
require __DIR__ . '/vendor/autoload.php';
use PhotoPrismUpload\API\PhotoPrism;
?>
<html>
<head>
</head>
<body></body>
<?php
if (!isset($_POST['submit'])) {
?>
<script>
window.tooLarge = false;
window.tooManyFiles = false;
function validateForm() {
const isInvalid = window.tooLarge || window.tooManyFiles;
console.log('Validating', window.tooLarge, window.tooManyFiles, isInvalid);
if (isInvalid) {
const errorDiv = document.getElementById('error');
errorDiv.innerText = '';
errorDiv.innerText += window.tooLarge ? 'Zu groß, Upload muss weniger als 200MB sein. ' : '';
errorDiv.innerText += window.tooManyFiles ? 'Zu viele Dateien, maximal 200 erlaubt. ' : '';
errorDiv.style.display = 'block';
}
return !isInvalid;
}
</script>
<form method="POST" enctype="multipart/form-data" onsubmit="return validateForm();">
<input multiple type="file" name="files[]" id="input" />
<input type="submit" name="submit" value="Upload" />
</form>
<div id="error" style="display:none"></div>
<script>
const input = document.getElementById('input')
input.addEventListener('change', (event) => {
const errorDiv = document.getElementById('error');
errorDiv.innerText = '';
errorDiv.style.display = 'none';
const target = event.target;
let totalSize = 0;
if (target.files) {
for (file of target.files) {
totalSize += file.size;
}
}
const sizeInMb = totalSize / 1000 / 1000;
window.tooLarge = sizeInMb >= 200;
console.log('Total size:', totalSize, 'too large: ', window.tooLarge);
window.tooManyFiles = target.files.length > 200;
console.log('Total files:', target.files.length, 'too many: ', window.tooManyFiles);
});
</script>
<?php
die();
}
$config = require(__DIR__ . '/config.php');
$api = new PhotoPrism($config);
try {
$api->login();
$api->getAlbums();
} catch (\Exception $e) {
die('Fehler: ' . $e->getMessage());
}