commit | author | age
|
9f6455
|
1 |
<?php |
DC |
2 |
//TODO ELIMINARE |
|
3 |
/*** |
|
4 |
* |
|
5 |
* Da base_64 a file |
|
6 |
* "$ php scripts\generate-string_64.php dGVzdG8gYSBjYXNvIA== |
|
7 |
* lanciando il comando sopra da terminale la stringa verrà automaticamente convertita all'interno del file "scripts/decoded_files/new_decoded_file.txt" |
|
8 |
* altrimenti sarà possibile inserire il secondo valore "false" per compiere il l'encode partendo da un file |
|
9 |
* "$ php scripts\generate-string_64.php C:\User\Documents\filename.txt |
|
10 |
* |
|
11 |
* Inserendo come primo parametro un path o una stringa 64 verrà automaticamente fatta la conversione |
|
12 |
* |
|
13 |
* //TODO terminare e fare un secondo script che genera l'array con i tre parametri che si attende il tool per ogni file da allegare |
|
14 |
* |
|
15 |
* include __DIR__ . '/ParamsBase64.php'; |
|
16 |
* |
|
17 |
* |
|
18 |
* $newParams64 = new ParamsBase64(); |
|
19 |
* |
|
20 |
* |
|
21 |
* if (isset($argv[1])) { |
|
22 |
* $newParams64->setStringValue($argv[1]); |
|
23 |
* } |
|
24 |
* |
|
25 |
* if (isset($argv[2])) { |
|
26 |
* $newParams64->setEncode($argv[2]); |
|
27 |
* } else if (isset($argv[1]) && is_file($argv[1])) { |
|
28 |
* $newParams64->setEncode(false); |
|
29 |
* } |
|
30 |
* |
|
31 |
* |
|
32 |
* function fileToBase64($filePath): string |
|
33 |
* { |
|
34 |
* if (!file_exists($filePath)) { |
|
35 |
* var_dump("File non trovato al path {$filePath}"); |
|
36 |
* die(); |
|
37 |
* } |
|
38 |
* |
|
39 |
* $fileContent = file_get_contents($filePath); |
|
40 |
* |
|
41 |
* //TODO refactoring |
|
42 |
* $newFile = fopen( __DIR__ . "\\encoded_files\\new_encoded_file.txt" , "w"); |
|
43 |
* fwrite($newFile, base64_encode($fileContent)); |
|
44 |
* fclose($newFile); |
|
45 |
* |
|
46 |
* return base64_encode($fileContent); |
|
47 |
* } |
|
48 |
* |
|
49 |
* function base64ToFile($base64String, $filePath) |
|
50 |
* { |
|
51 |
* $decodedData = base64_decode($base64String); |
|
52 |
* $newFile = fopen($filePath, "w"); |
|
53 |
* fwrite($newFile, $decodedData); |
|
54 |
* fclose($newFile); |
|
55 |
* } |
|
56 |
* |
|
57 |
* if ($newParams64->isEncode()) { |
|
58 |
* var_dump("base64ToFile"); |
|
59 |
* base64ToFile($newParams64->getStringValue(), $newParams64->getPath()); |
|
60 |
* } else { |
|
61 |
* var_dump("fileToBase64"); |
|
62 |
* var_dump("La tua stringa in base64: " . '"' . fileToBase64($newParams64->getStringValue())) . '"'; |
|
63 |
* } |
|
64 |
*/ |
|
65 |
//TODO ELIMINARE |
|
66 |
|
|
67 |
include __DIR__ . '/Base64.php'; |
|
68 |
//Base64::encode("C:\Users\Simone Lollini\\decoded_64.txt", true); |
|
69 |
//Base64::decode("C:\Users\Simone Lollini\\encoded_64.txt", true); |
|
70 |
//Base64::encode( "test-encoded data",false,true,"C:\Users\Simone Lollini\Desktop\mega-test.txt"); |
|
71 |
|