mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
La clé du pdf est contruite dés la page d'accueil
This commit is contained in:
parent
9ae3a63551
commit
3a7886acb2
17
app.php
17
app.php
@ -15,12 +15,18 @@ if(!is_dir($f3->get('UPLOADS'))) {
|
|||||||
}
|
}
|
||||||
$f3->route('GET /',
|
$f3->route('GET /',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$f3->set('key', $f3->get('PARAMS.key'));
|
$f3->set('key', hash('md5', uniqid().rand()));
|
||||||
echo View::instance()->render('index.html.php');
|
echo View::instance()->render('index.html.php');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$f3->route('POST /upload',
|
$f3->route('POST /upload',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
|
$key = $f3->get('POST.key');
|
||||||
|
|
||||||
|
if(!$key || !preg_match('/^[0-9a-z]+$/', $key)) {
|
||||||
|
$f3->error(403);
|
||||||
|
}
|
||||||
|
|
||||||
$fileName = null;
|
$fileName = null;
|
||||||
$files = Web::instance()->receive(function($file,$formFieldName){
|
$files = Web::instance()->receive(function($file,$formFieldName){
|
||||||
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
|
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
|
||||||
@ -29,20 +35,21 @@ $f3->route('POST /upload',
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}, true, function($fileBaseName, $formFieldName) use (&$fileName) {
|
}, true, function($fileBaseName, $formFieldName) use (&$fileName, $key) {
|
||||||
$fileName = $fileBaseName;
|
$fileName = $fileBaseName;
|
||||||
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).".pdf";
|
return $key.".pdf";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$filePdf = null;
|
||||||
foreach($files as $file => $valid) {
|
foreach($files as $file => $valid) {
|
||||||
if(!$valid) {
|
if(!$valid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = str_replace(".pdf", "", basename($file));
|
$filePdf = $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$key) {
|
if(!$filePdf) {
|
||||||
$f3->error(403);
|
$f3->error(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<h1 class="display-5 fw-bold"><i class="bi bi-vector-pen"></i> Signer un PDF</h1>
|
<h1 class="display-5 fw-bold"><i class="bi bi-vector-pen"></i> Signer un PDF</h1>
|
||||||
<div class="col-lg-3 mx-auto">
|
<div class="col-lg-3 mx-auto">
|
||||||
<form id="form_pdf_upload" action="/upload" method="POST" class="row g-3" enctype="multipart/form-data">
|
<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">
|
<div class="col-12">
|
||||||
<label for="input_pdf_upload" class="form-label">Choisir un PDF</label>
|
<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">
|
<input id="input_pdf_upload" class="form-control form-control-lg" name="pdf" type="file">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user