-
Notifications
You must be signed in to change notification settings - Fork 1
/
15_file_upload.php
64 lines (49 loc) · 1.85 KB
/
15_file_upload.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
<?php
//checking
if(isset($_POST['submit'])){
///
if(!empty($_FILES['upload']['name'])){
// print_r($_FILES);
$file_name = $_FILES['upload']['name'];
$file_size = $_FILES['upload']['size'];
$file_tmp = $_FILES['upload']['tmp_name'];
$target_dir = "uploads/$file_name";
//get file ext
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($Ffile_name));
//validate file ext
if(in_array($file_ext, $allowed_ext)){
if($file_size <= 1000000){
move_uploaded_file($file_tmp, $target_dir);
$massage = '<p style="color:green;">file uploaded successfully</p><br> <p style="color:red;">arquivo enviado com sucesso</p><br>';
}else{
$massage = '<p style="color:red;">File is too large</p><br> <p style="color:red;">O Arquivo e muito grande</p><br>';
}
}else{
$massage = '<p style="color:red;">Please choose a file</p><br> <p style="color:red;">Escolha um arquivo</p><br>';
}
}else {
$massage = '<p style=" Invalid file</p><br> <p style="color:red;"> arquivo/ficheiro Invalido </p><br>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SEL']; ?>" method="POST" enctype="multipart/form-data">
<di>
<label for="upload">Eng: Select image to upload <br> Pt: Seleciona imagem para submeter</label>
<!--fild | campo -->
<input type="file" name="upload">
<!--Button -- botao para submeter -->
<input type="submit" value="submit" name='submit'>
</di>
</form>
</body>
</html>