-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_picture.php
More file actions
37 lines (31 loc) · 1.15 KB
/
Copy pathupload_picture.php
File metadata and controls
37 lines (31 loc) · 1.15 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
<?php
session_start();
include 'db_user_connection.php';
if (!isset($_SESSION['username'])) {
header("Location: index.html");
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$current_username = $_SESSION['username'];
// Get the uploaded image file
if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] === UPLOAD_ERR_OK) {
$image = file_get_contents($_FILES['profile_picture']['tmp_name']); // Get image content
// Updating images in the database
$stmt = $conn->prepare("UPDATE users SET picture = ? WHERE username = ?");
$stmt->bind_param("bs", $image, $current_username);
$stmt->send_long_data(0, $image);
if ($stmt->execute()) {
echo "Profile picture updated successfully.";
} else {
echo "Error updating profile picture: " . $stmt->error;
}
$stmt->close();
$conn->close();
header("Location: profile.php"); // Redirect to personal information page after successful upload
exit();
}
else {
echo "Error: Please upload a valid image file.";
}
}
?>