-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadfile.php
More file actions
50 lines (43 loc) · 1.18 KB
/
uploadfile.php
File metadata and controls
50 lines (43 loc) · 1.18 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
<?php include 'filemenu.php'; ?>
<div class="container">
<div class="row" style="text-align:center;margin-top:3%">
<div class="col-3">
</div>
<div class="col-6">
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" >
<input type="submit" value="Upload" name="upload" class="btn btn-primary w-50 mt-2">
</form>
<?php
if(isset($_POST['upload'])){
$file=$_FILES['file'];
$file_name=$file['name'];
$file_tmp=$file['tmp_name'];
$file_size=$file['size'];
$file_error=$file['error'];
$file_location="../phpfiles/".$file_name;
if(empty($file_name)){
echo 'Insira algum ficheiro para inserir!';
}else{
//Tipo de ficheiro
$file_ext=explode('.',$file_name);
$file_ext=strtolower(end($file_ext));
//Ficheiros permitidos
$allowed=array('txt','xlsx','xls','xml','jpg','png');
if(in_array($file_ext,$allowed)){
if($file_error===1){
echo 'Formato não suportado';
}else{
if(move_uploaded_file($file_tmp,$file_location)){
echo 'File inserido com sucesso!';
}
}
}else{
echo 'Formato do ficheiro não suportado!';
}
}
}
?>
</div>
</div>
</div>