-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
64 lines (52 loc) · 2 KB
/
Copy pathcreate.php
File metadata and controls
64 lines (52 loc) · 2 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
<?php
$pdo = require 'db.php';
$uploadsDir = "uploads/";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_SPECIAL_CHARS);
$email = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);
$phone = filter_input(INPUT_POST, "phone", FILTER_SANITIZE_NUMBER_INT);
if ($name && $email && $phone && isset($_FILES["image"])) {
if (!is_dir($uploadsDir)) {
mkdir($uploadsDir, 0777, true);
}
$imageName = time() . "_" . basename($_FILES["image"]["name"]);
$imagePath = $uploadsDir . $imageName;
if (move_uploaded_file($_FILES["image"]["tmp_name"], $imagePath)) {
$stmt = $pdo->prepare("INSERT INTO contacts (id, name, email, phone, image) VALUES (:id, :name, :email, :phone, :image)");
$stmt->execute([
':id' => uniqid(),
':name' => $name,
':email' => $email,
':phone' => $phone,
':image' => $imagePath
]);
echo "Contact added.";
} else {
echo "Failed to upload image.";
}
} else {
echo "Invalid input.";
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<label for="name">Name:</label>
<input id="name" type="text" name="name" placeholder="Enter your name" required />
<label for="email">Email:</label>
<input id="email" type="email" name="email" placeholder="Enter your email" required />
<label for="phone">Phone:</label>
<input id="phone" type="tel" name="phone" placeholder="Enter your phone number" />
<label for="image">Image:</label>
<input id="image" type="file" name="image" accept="image/*" />
<input type="submit" value="Submit" />
</form>
</body>
</html>