1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

Le nom de fichier du pdf est stocké en js avant l'upload ce qui évite de

passer en session après
This commit is contained in:
Vincent LAURENT 2021-11-11 10:06:42 +01:00
parent 3a7886acb2
commit 19025fa07f
3 changed files with 9 additions and 18 deletions

13
app.php
View File

@ -27,7 +27,6 @@ $f3->route('POST /upload',
$f3->error(403);
}
$fileName = null;
$files = Web::instance()->receive(function($file,$formFieldName){
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
@ -35,8 +34,7 @@ $f3->route('POST /upload',
}
return true;
}, true, function($fileBaseName, $formFieldName) use (&$fileName, $key) {
$fileName = $fileBaseName;
}, true, function($fileBaseName, $formFieldName) use ($key) {
return $key.".pdf";
});
@ -53,20 +51,13 @@ $f3->route('POST /upload',
$f3->error(403);
}
if($fileName) {
$f3->set('SESSION.fileName', $fileName);
}
return $f3->reroute('/'.$key);
}
);
$f3->route('GET /@key',
function($f3) {
$f3->set('key', $f3->get('PARAMS.key'));
if($f3->get('SESSION.fileName')) {
$f3->set('fileName', $f3->get('SESSION.fileName'));
$f3->clear('SESSION.fileName');
}
echo View::instance()->render('pdf.html.php');
}
);

View File

@ -33,7 +33,14 @@
</footer>
<script>
var key = "<?php echo $key ?>";
var pdfHistory = {};
if(localStorage.getItem('pdfHistory')) {
pdfHistory = JSON.parse(localStorage.getItem('pdfHistory'));
}
document.getElementById('input_pdf_upload').addEventListener('change', function(event) {
pdfHistory[key] = { filename: document.getElementById('input_pdf_upload').files[0].name }
localStorage.setItem('pdfHistory', JSON.stringify(pdfHistory));
document.getElementById('form_pdf_upload').submit();
});
async function uploadFromUrl(url) {

View File

@ -151,13 +151,6 @@
if(localStorage.getItem('pdfHistory')) {
pdfHistory = JSON.parse(localStorage.getItem('pdfHistory'));
}
<?php if(isset($fileName)): ?>
pdfHistoryItem = {};
pdfHistoryItem.filename = "<?php echo $fileName ?>";
pdfHistoryItem.key = "<?php echo $key ?>";
pdfHistory[pdfHistoryItem.key] = pdfHistoryItem;
localStorage.setItem('pdfHistory', JSON.stringify(pdfHistory));
<?php endif;?>
if(pdfHistory["<?php echo $key ?>"]) {
filename = pdfHistory["<?php echo $key ?>"].filename;
}