From 8b6f8c4e5891cd42941bca715c545102667b2a19 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Tue, 21 Sep 2021 23:44:34 +0200 Subject: [PATCH] Route pour appeler le PDF et dossier templates --- app.php | 23 +++++++++++++++------- index.html.php => templates/index.html.php | 0 pdf.html.php => templates/pdf.html.php | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) rename index.html.php => templates/index.html.php (100%) rename pdf.html.php => templates/pdf.html.php (98%) diff --git a/app.php b/app.php index a1b3e97..97c0757 100644 --- a/app.php +++ b/app.php @@ -1,7 +1,10 @@ set('DEBUG',1); +$f3->set('ROOT', __DIR__); +$f3->set('UI', $f3->get('ROOT')."/templates/"); $f3->set('UPLOADS', $f3->get('ROOT').'/data/'); if(!is_dir($f3->get('UPLOADS'))) { @@ -10,7 +13,7 @@ if(!is_dir($f3->get('UPLOADS'))) { $f3->route('GET /', function($f3) { $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', @@ -33,7 +36,7 @@ $f3->route('POST /upload', continue; } $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) { @@ -46,7 +49,13 @@ $f3->route('POST /upload', $f3->route('GET /@key', function($f3) { $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', @@ -96,16 +105,16 @@ $f3->route('POST /@key/save', $svgFiles = ""; foreach($svgData as $index => $svgItem) { - $svgFile = $f3->get('UPLOADS').'/'.$key.'_'.$index.'.svg'; + $svgFile = $f3->get('UPLOADS').$key.'_'.$index.'.svg'; file_put_contents($svgFile, $svgItem); $svgFiles .= $svgFile . " "; } - 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("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')); - Web::instance()->send($f3->get('UPLOADS').'/'.$key.'_signe.pdf'); + Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf'); } ); $f3->run(); \ No newline at end of file diff --git a/index.html.php b/templates/index.html.php similarity index 100% rename from index.html.php rename to templates/index.html.php diff --git a/pdf.html.php b/templates/pdf.html.php similarity index 98% rename from pdf.html.php rename to templates/pdf.html.php index 87a5024..ca7f6ac 100644 --- a/pdf.html.php +++ b/templates/pdf.html.php @@ -53,7 +53,7 @@