-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.php
More file actions
76 lines (65 loc) · 1.53 KB
/
files.php
File metadata and controls
76 lines (65 loc) · 1.53 KB
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
<!DOCTYPE>
<html>
<head>
</head>
<body>
<?php
$file=fopen("file.txt","a") or die("Erro a abrir o ficheiro!");
?>
<form method="post">
<input type="text" name="nome" placeholder="Inserir Nome">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="open" value="Check File">
<input type="text" name="search" placeholder="Search Nome">
<input type="submit" name="searchs" value="Search">
<input type="submit" name="modificar" value="Modificar">
<input type="submit" name="criar" value="Menu de Files">
<input type="submit" name="clear" value="Clear">
</form>
<?php
if(isset($_POST["submit"])){
$nome=$_POST["nome"];
if(empty($nome)){
echo 'Insira algo para colocar no ficheiro!';
}else{
fwrite($file, $nome."<br>");
echo "Inserido com sucesso!<br>";
fclose($file);
}
}
if(isset($_POST["open"])){
echo "Conteudo do ficheiro:<br>" ;
$read=file('file.txt');
foreach($read as $name){
echo $name."<br>";
}
}
if(isset($_POST["searchs"])){
$search=$_POST["search"];
$read='file.txt';
if(empty($search)){
echo 'Insira um nome para pesquisar!';
}else{
$content=file_get_contents($read);
$lastsearch="/$search/";
if(preg_match_all($lastsearch, $content, $result)){
echo 'Encontrou!';
echo implode($result[0]);
}else{
echo 'Nome não existente!';
}
}
}
if(isset($_POST["modificar"])){
header("Location:editfile.php");
}
if(isset($_POST["criar"])){
header('Location: filemenu.php');
}
if(isset($_POST["clear"])){
file_put_contents("file.txt","");
echo 'File apagado!';
}
?>
</body>
</html>