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

Nom de fichier aléatoire avant le move de l'upload et également pour

l'action d'upload d'image pour conversion en svg
Nettoyage des fichiers non utilisés
This commit is contained in:
Vincent LAURENT 2021-10-31 22:05:48 +01:00
parent 476adfa494
commit 20ae508289

22
app.php
View File

@ -28,15 +28,17 @@ $f3->route('POST /upload',
return false;
}
return true;
}, true);
}, true, function($fileBaseName, $formFieldName) {
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).".pdf";
});
$key = null;
foreach($files as $file => $valid) {
if(!$valid) {
continue;
}
$key = substr(hash('sha256', hash_file('sha256', $file).uniqid()), 0, 24);
rename($file, $f3->get('UPLOADS').$key.'.pdf');
$key = str_replace(".pdf", "", basename($file));
}
if(!$key) {
@ -69,8 +71,12 @@ $f3->route('POST /image2svg',
return false;
}
return true;
}, true);
}, true, function($fileBaseName, $formFieldName) {
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).strrchr($fileBaseName, '.');
});
$imageFile = null;
foreach($files as $file => $valid) {
@ -90,6 +96,7 @@ $f3->route('POST /image2svg',
header('Content-Type: image/svg+xml');
echo file_get_contents($imageFile.".svg");
array_map('unlink', glob($imageFile."*"));
}
);
$f3->route('POST /@key/save',
@ -104,11 +111,14 @@ $f3->route('POST /@key/save',
$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'));
Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf');
array_map('unlink', glob($f3->get('UPLOADS').$key."_*.svg"));
unlink($f3->get('UPLOADS').$key.'.svg.pdf');
unlink($f3->get('UPLOADS').$key.'_signe.pdf');
}
);