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