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

Share upload file original and redirect to a new route with a hash

This commit is contained in:
Vincent LAURENT 2022-03-31 11:46:03 +02:00
parent b3c7c186a8
commit a41155c950
2 changed files with 40 additions and 0 deletions

39
app.php
View File

@ -53,6 +53,18 @@ $f3->route('GET /signature',
echo View::instance()->render('signature.html.php');
}
);
$f3->route('GET /signature/@hash',
function($f3, $param) {
$f3->set('hash', $param['hash']);
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
$f3->set('maxPage', ini_get('max_file_uploads') - 1);
echo View::instance()->render('signature.html.php');
}
);
$f3->route('GET /organization',
function($f3) {
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
@ -151,6 +163,33 @@ $f3->route('POST /sign',
}
);
$f3->route('POST /share',
function($f3) {
$hash = substr(hash('sha512', uniqid().rand()), 0, 20);
$sharingFolder = $f3->get('STORAGE').$hash."/";
$f3->set('UPLOADS', $sharingFolder);
mkdir($sharingFolder);
$filename = "original.pdf";
$files = Web::instance()->receive(function($file,$formFieldName){
if(strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) {
$f3->error(403);
}
return true;
}, false, function($fileBaseName, $formFieldName) use ($filename) {
return $filename;
});
if(!count($files)) {
$f3->error(403);
}
$f3->reroute('/signature/'.$hash);
}
);
$f3->route('POST /organize',
function($f3) {
$filename = null;

View File

@ -28,6 +28,7 @@ var loadPDF = async function(pdfBlob, filename) {
type: 'application/pdf'
}));
document.getElementById('input_pdf').files = dataTransfer.files;
document.getElementById('input_pdf_share').files = dataTransfer.files;
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {