La clé du pdf est contruite dés la page d'accueil

This commit is contained in:
Vincent LAURENT 2021-11-11 09:47:51 +01:00
parent 9ae3a63551
commit 3a7886acb2
2 changed files with 13 additions and 5 deletions

17
app.php
View File

@ -15,12 +15,18 @@ if(!is_dir($f3->get('UPLOADS'))) {
}
$f3->route('GET /',
function($f3) {
$f3->set('key', $f3->get('PARAMS.key'));
$f3->set('key', hash('md5', uniqid().rand()));
echo View::instance()->render('index.html.php');
}
);
$f3->route('POST /upload',
function($f3) {
$key = $f3->get('POST.key');
if(!$key || !preg_match('/^[0-9a-z]+$/', $key)) {
$f3->error(403);
}
$fileName = null;
$files = Web::instance()->receive(function($file,$formFieldName){
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
@ -29,20 +35,21 @@ $f3->route('POST /upload',
}
return true;
}, true, function($fileBaseName, $formFieldName) use (&$fileName) {
}, true, function($fileBaseName, $formFieldName) use (&$fileName, $key) {
$fileName = $fileBaseName;
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).".pdf";
return $key.".pdf";
});
$filePdf = null;
foreach($files as $file => $valid) {
if(!$valid) {
continue;
}
$key = str_replace(".pdf", "", basename($file));
$filePdf = $file;
}
if(!$key) {
if(!$filePdf) {
$f3->error(403);
}

View File

@ -14,6 +14,7 @@
<h1 class="display-5 fw-bold"><i class="bi bi-vector-pen"></i> Signer un PDF</h1>
<div class="col-lg-3 mx-auto">
<form id="form_pdf_upload" action="/upload" method="POST" class="row g-3" enctype="multipart/form-data">
<input id="input_key" name="key" type="hidden" value="<?php echo $key ?>">
<div class="col-12">
<label for="input_pdf_upload" class="form-label">Choisir un PDF</label>
<input id="input_pdf_upload" class="form-control form-control-lg" name="pdf" type="file">