-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgupdate.php
39 lines (32 loc) · 1.43 KB
/
imgupdate.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
<?php
session_start(); // Start the session if not already started
$conn = new mysqli("localhost", "root", "", "krifydemo");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Database connection and other setup
// Sanitize input
$id = $_POST['image_id'];
// echo $id; exit;
// Validate uploaded file
$allowedTypes = ['image/jpeg', 'image/png']; // Adjust allowed types as needed
$maxFileSize = 5 * 1024 * 1024; // 5 MB
if (in_array($_FILES['image']['type'], $allowedTypes) && $_FILES['image']['size'] <= $maxFileSize) {
$newImagePath = "uploads/" . $_FILES['image']['name'];
if (move_uploaded_file($_FILES['image']['tmp_name'], $newImagePath)) {
// Update image path in the database for the user using prepared statement
// echo $newImagePath."jskdshds".$id; exit;
// $query = "UPDATE images SET image_path = $newImagePath WHERE id = $id";
$query = "UPDATE images SET image_path = '$newImagePath' WHERE id = '$id'";
// echo $query; exit;
$result = mysqli_query($conn, $query);
// Execute prepared statement and handle result
echo "Image updated successfully!";
header("Location: display.php");
exit;
} else {
echo "Error updating image.";
}
} else {
echo "Invalid image format or size.";
}
}
?>