-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenfile.php
123 lines (103 loc) · 2.94 KB
/
openfile.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
include 'filemenu.php';
//lista de files
$dir="Files/";
//raiz
$files=glob($dir."*.txt");
//Nome e Formato do Ficheiro
$filestxt=glob($dir,"*.txt");
$filexlsx=glob("*.xlsx");
$filexls=glob("*.xls");
$filexml=glob("*.xml");
$filejpg=glob("*.jpg");
$filepng=glob("*.png");
?>
<div class="container">
<div class="row" style="text-align:center;margin-top:3%">
<div class="col-2">
</div>
<div class="col-8">
<form method="post">
<select name="files" id="framework" class="form-control">
<?php
//Mostar todos os files dentro da pasta
foreach($filestxt as $allfiles){
str_replace("Files/"," ",$allfiles);
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
foreach($filexlsx as $allfiles){
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
foreach($filexls as $allfiles){
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
foreach($filexml as $allfiles){
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
foreach($filejpg as $allfiles){
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
foreach($filepng as $allfiles){
echo "<option value=".$allfiles.">".$allfiles."</option>";
}
echo '</select></td><td><input type="submit" name="open" value="Abrir File" class="btn btn-primary w-100 mt-3"></form></td></tr>';
if(isset($_POST["open"])){
$file=$_POST["files"];
if(strpos($file,'.txt')!==false){
//Ler ficheiro Text
$read=file($file);
foreach($read as $name){
echo $name."<br>";
}
}else if(strpos($file,'.xlsx')!==false){
//Ler ficheiro Excel
include 'Classes/PHPExcel/IOFactory.php';
$filename=$file;
//Criar uma variavel para ler o ficheiro Excel
$excelReader=PHPExcel_IOFactory::createReaderForFile($filename);
//Criar uma variavel que vai conter o ficheiro, o objeto do ficheiro Excel
$excelObj=$excelReader->load($filename);
//Obter o Excel
$sheet=$excelObj->getActiveSheet();
//Obter a ultima Row do ficheiro Excel
$lastRow=$sheet->getHighestRow();
//Obter a ultima Coluna do ficheiro Excel
$lastCol=$sheet->getHighestColumn();
echo "<table class='table table-bordered' style='text-align:center;'>";
echo "<tr><td></td>";
for($cc='A';$cc<=$lastCol;$cc++){
echo "<td>".$cc."</td>";
}
echo "</tr>";
for($r=1;$r<=$lastRow;$r++){
echo "<tr><td>".$r."</td>";
for($c='A'; $c<=$lastCol;$c++){
echo "<td>".$sheet->getCell($c.$r)->getValue()."</td>";
}
echo "<tr>";
}
echo "</table>";
}else if(strpos($file,'.xls')!==false){
//Ler ficheiro Excel
echo 'Ficheiro Excel';
}else if(strpos($file,'.xml')!==false){
//Ler ficheiro XML
echo 'Ficheiro XML';
}
//Ler Imagens
//Imagem tipo PNG
else if(strpos($file,'.png')!==false){
echo "<img src=".$file.">";
}
//Imagem tipo JPG
else if(strpos($file,'.jpg')!==false){
echo "<img src=".$file.">";
}
else{
echo 'Erro ao ler ficheiro!';
}
}
?>
</div>
</div>
</div>