-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd-reader.php
More file actions
53 lines (44 loc) · 809 Bytes
/
cmd-reader.php
File metadata and controls
53 lines (44 loc) · 809 Bytes
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
<?php
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
$index = $_REQUEST["index"];
$archivo = $_REQUEST["archivo"];
if (file_exists($archivo)) {
$archivo = fopen($archivo, 'r');
if ($index > 0) {
for ($I = 0; $I < $index; $I++) {
$linea = trim(fgets($archivo));
}
}
else {
$I = 0;
}
$texto = '';
while ($linea = fgets($archivo)) {
$linea = mb_convert_encoding(trim($linea), 'CP1252');
if ($linea == "FIN") {
$I = 'FIN';
}
else {
$I++;
$texto.= "\n<br>".$linea;
}
}
fclose($archivo);
if ($I == 'FIN') {
unlink($_REQUEST["archivo"]);
}
$resultado = [
"I" => $I,
"texto" => $texto
];
}
else {
$resultado = [
"I" => 0,
"texto" => ''
];
}
header('Content-Type: application/json');
$resultado = json_encode($resultado);
echo $resultado;