forked from bitoid/php-bootcamp-week-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.php
More file actions
68 lines (56 loc) · 1.79 KB
/
validate.php
File metadata and controls
68 lines (56 loc) · 1.79 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
<style>
.img{
width:200px;
height:200px;
display:block;
}
</style>
<?php
if($_SERVER('REQUEST_METHOD') == 'POST'){
if(!ctype_alpha($_POST['firstname'])){
echo "it is an invalid name!";
}
if(!ctype_alpha($_POST['lastname'])){
echo "it is an invalid lastname!";
}
}
?>
<?php
if(isset($_POST['submit'])){
echo $_POST ['firstname'] . "\n";
echo $_POST ['lastname'];
$file = $_FILES['image'];
$fileName = $_FILES['image']['name'];
$fileTmpName = $_FILES['image']['tmp_name'];
$fileError = $_FILES['image']['error'];
$fileType = $_FILES['image']['type'];
$fileSize = $_FILES['image']['size'];
//seperate the file name and the dot after it
$fileExt = explode('.', $fileName);
//make the second data lowercase after seperating the file name and the dot
$fileActualExt = strtolower(end($fileExt));
//only allow jpg jpeg png pdf
$allowed = array('jpg', 'jpeg', 'png', 'pdf', 'svg', 'raw', 'tif', 'tiff', 'eps');
//let's check if user has a allowing image
if(in_array($fileActualExt, $allowed)){
//let's check if we had an error inside the file info
if($fileError === 0){
//let's check for file size
if($fileSize < 1000000){
//let's make the image's name an unique and then add the type
// $fileNameNew = uniqid('', true).".".$fileActualExt;
//let's make the file destination
$fileDestination = 'uploads/'.$fileName;
move_uploaded_file($fileTmpName, $fileDestination);
echo "<img class='img' src='uploads/".$fileName."'>";
}else{
echo "your file is too big";
}
}else{
echo "It's an error";
}
}else{
echo "You cannot upload files of this type!";
}
}
?>