-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
81 lines (70 loc) · 2.82 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
$id = $_GET['id'];
$dbHost = "localhost:3306";
$dbUsername = "root";
$dbPassword = "root";
$dbName = "database".$id;
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$name = $_POST['text'];
$total = count($fileName);
for( $i=0 ; $i < $total ; $i++ ) {
$b=false;
$n='';
$file = $_FILES['file'][$i];
$fileName = $_FILES['file']['name'][$i];
$fileTmpName = $_FILES['file']['tmp_name'][$i];
$fileSize = $_FILES['file']['size'][$i];
$fileError = $_FILES['file']['error'][$i];
$fileType = $_FILES['file']['type'][$i];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)){
if ($fileError == 0){
if ($fileSize < 5000000){
$fileNameNew = uniqid('', true).".".$fileActualExt;
if (!file_exists('worker faces'.$id.'/'.$_POST["text"])) {
mkdir('worker faces'.$id.'/'.$_POST["text"], 0777, true);
}
$fileDestination = 'worker faces'.$id.'/'.$_POST["text"].'/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "SELECT * FROM `images`";
$result = $db->query($sql);
if ($result->num_rows> 0) {
while($row = $result->fetch_assoc()) {
if((strcmp($row[name],$name)==0)){
echo "<h3>".$total."<h3/>";
$n=$row[imagename].$fileDestination.'-';
$s = "UPDATE `images` SET `imagename`='".$n."' WHERE name='".$row[name]."'";
mysqli_query($db,$s);
$b=true;
$n="";
break;
}
}
if($b!=true){
$query = "insert into images (name,imagename) values('".$name."','".$fileDestination.'-'."')";
mysqli_query($db,$query);
}
}else{
$query = "insert into images (name,imagename) values('".$name."','".$fileDestination.'-'."')";
mysqli_query($db,$query);
}
} else{
echo "Your file is too big.";
}
}else{
echo "There was an error uploading your file.";
}
} else{
echo "You cannot upload files of this type.";
}
}
$db->close();
header("Location: /add_an_employee.php?id=".$id);
?>