mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
Route pour appeler le PDF et dossier templates
This commit is contained in:
parent
3eef282ce6
commit
8b6f8c4e58
23
app.php
23
app.php
@ -1,7 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$f3 = require(__DIR__.'/vendor/fatfree/lib/base.php');
|
$f3 = require(__DIR__.'/vendor/fatfree/lib/base.php');
|
||||||
|
|
||||||
$f3->set('DEBUG',1);
|
$f3->set('DEBUG',1);
|
||||||
|
$f3->set('ROOT', __DIR__);
|
||||||
|
$f3->set('UI', $f3->get('ROOT')."/templates/");
|
||||||
$f3->set('UPLOADS', $f3->get('ROOT').'/data/');
|
$f3->set('UPLOADS', $f3->get('ROOT').'/data/');
|
||||||
|
|
||||||
if(!is_dir($f3->get('UPLOADS'))) {
|
if(!is_dir($f3->get('UPLOADS'))) {
|
||||||
@ -10,7 +13,7 @@ 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', $f3->get('PARAMS.key'));
|
||||||
echo View::instance()->render('../index.html.php');
|
echo View::instance()->render('index.html.php');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$f3->route('POST /upload',
|
$f3->route('POST /upload',
|
||||||
@ -33,7 +36,7 @@ $f3->route('POST /upload',
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$key = substr(hash('sha256', hash_file('sha256', $file).uniqid()), 0, 24);
|
$key = substr(hash('sha256', hash_file('sha256', $file).uniqid()), 0, 24);
|
||||||
rename($file, $f3->get('UPLOADS').'/'.$key.'.pdf');
|
rename($file, $f3->get('UPLOADS').$key.'.pdf');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$key) {
|
if(!$key) {
|
||||||
@ -46,7 +49,13 @@ $f3->route('POST /upload',
|
|||||||
$f3->route('GET /@key',
|
$f3->route('GET /@key',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$f3->set('key', $f3->get('PARAMS.key'));
|
$f3->set('key', $f3->get('PARAMS.key'));
|
||||||
echo View::instance()->render('../pdf.html.php');
|
echo View::instance()->render('pdf.html.php');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$f3->route('GET /@key/pdf',
|
||||||
|
function($f3) {
|
||||||
|
$key = $f3->get('PARAMS.key');
|
||||||
|
Web::instance()->send($f3->get('UPLOADS').$key.'.pdf');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$f3->route('POST /image2svg',
|
$f3->route('POST /image2svg',
|
||||||
@ -96,16 +105,16 @@ $f3->route('POST /@key/save',
|
|||||||
|
|
||||||
$svgFiles = "";
|
$svgFiles = "";
|
||||||
foreach($svgData as $index => $svgItem) {
|
foreach($svgData as $index => $svgItem) {
|
||||||
$svgFile = $f3->get('UPLOADS').'/'.$key.'_'.$index.'.svg';
|
$svgFile = $f3->get('UPLOADS').$key.'_'.$index.'.svg';
|
||||||
file_put_contents($svgFile, $svgItem);
|
file_put_contents($svgFile, $svgItem);
|
||||||
$svgFiles .= $svgFile . " ";
|
$svgFiles .= $svgFile . " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $f3->get('UPLOADS').'/'.$key.'.svg.pdf', $svgFiles));
|
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $f3->get('UPLOADS').$key.'.svg.pdf', $svgFiles));
|
||||||
shell_exec(sprintf("pdftk %s multibackground %s output %s", $f3->get('UPLOADS').'/'.$key.'.svg.pdf', $f3->get('UPLOADS').'/'.$key.'.pdf', $f3->get('UPLOADS').'/'.$key.'_signe.pdf'));
|
shell_exec(sprintf("pdftk %s multibackground %s output %s", $f3->get('UPLOADS').$key.'.svg.pdf', $f3->get('UPLOADS').$key.'.pdf', $f3->get('UPLOADS').$key.'_signe.pdf'));
|
||||||
|
|
||||||
Web::instance()->send($f3->get('UPLOADS').'/'.$key.'_signe.pdf');
|
Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$f3->run();
|
$f3->run();
|
@ -53,7 +53,7 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/fabric@4.4.0/dist/fabric.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/fabric@4.4.0/dist/fabric.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/signature_pad@3.0.0-beta.3/dist/signature_pad.umd.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/signature_pad@3.0.0-beta.3/dist/signature_pad.umd.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var url = '/data/<?php echo $key ?>.pdf';
|
var url = '/<?php echo $key ?>/pdf';
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/app.js"></script>
|
<script src="/js/app.js"></script>
|
||||||
<script src="/js/opentype.min.js"></script>
|
<script src="/js/opentype.min.js"></script>
|
Loading…
x
Reference in New Issue
Block a user