-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatefile.php
58 lines (52 loc) · 1.27 KB
/
createfile.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
<?php include 'filemenu.php' ?>
<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">
<div class="form-group">
<input type="text" name="filetit" placeholder="Nome do File" class="form-control">
</div>
<input type="submit" name="createfile" value="Criar File" class="btn btn-primary w-100">
</form>
<script>
function successCreate(){
alert('File criado com sucesso!');
}
function errorCreate(){
alert('Nome do ficheiro já existe!');
}
function errorCreate2(){
alert('Não pode deixar o nome do ficheiro vazio!');
}
</script>
<?php
if(isset($_POST["createfile"])){
$filename=$_POST["filetit"];
$checkname=0;
//nome do file
$filestxt=glob("*.txt");
$filexlsx=glob("*.xlsx");
$filexls=glob("*.xls");
$filexml=glob("*.xml");
$checkname=0;
foreach($filestxt as $allfiles){
if($filename.".txt"===$allfiles){
$checkname=1;
}
}
if(empty($filename)){
echo '<script>errorCreate2()</script>';
}else if($checkname==1){
//Verificar se já existe um ficheiro com o mesmo Nome
echo '<script>errorCreate()</script>';
}else{
fopen($filename.'.txt','w');
echo '<script>successCreate()</script>';
}
}
?>
</div>
</div>
</div>