-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathca-profile-picture.php
77 lines (66 loc) · 3.01 KB
/
ca-profile-picture.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
<?php
session_start();
error_reporting(0);
// Database connection
include('database.php');
session_start();
if(!isset($_SESSION['id']))
{
header('location:ca-login.php');
}
$cadmin_id = $_SESSION['id'];
$d_sql = "SELECT * FROM class_admin WHERE id = '$cadmin_id' ";
$d_result = mysqli_query($data, $d_sql);
$d_info = mysqli_fetch_assoc($d_result);
// File upload
$targetDir = "Profile/"; // Directory to store uploaded images
$targetFile = $targetDir . basename($_FILES["profile_picture"]["name"]); // Path of the uploaded file
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// Check if image file is a valid image
$check = getimagesize($_FILES["profile_picture"]["tmp_name"]);
if ($check === false)
{
$_SESSION['dp_invalid'] = 'Invalid image file!';
header("location:ca-profile.php");
$uploadOk = 0;
}
// Check file size (optional)
if ($_FILES["profile_picture"]["size"] > 5000000)
{
$_SESSION['dp_large'] = 'This file is too large. Try uploading a small one!';
header("location:ca-profile.php");
$uploadOk = 0;
}
// Allow only certain file formats (optional)
if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png" && $imageFileType != "gif")
{
$_SESSION['dp_format'] = 'Only JPG, JPEG, PNG, and GIF files are allowed!';
header("location:ca-profile.php");
$uploadOk = 0;
}
// If file upload is OK, move the uploaded file to the target directory
if ($uploadOk == 1)
{
if (move_uploaded_file($_FILES["profile_picture"]["tmp_name"], $targetFile))
{
$profilePicturePath = $targetFile;
$sql = "UPDATE class_admin SET profile_picture = '$profilePicturePath' WHERE id = '$cadmin_id'";
if ($data->query($sql) === true)
{
$_SESSION['dp_change'] = 'Your Profile picture was updated!';
header("location:ca-profile.php");
}
else
{
$_SESSION['no_dp_database'] = 'Error updating profile picture in the database!';
header("location:ca-profile.php");
}
}
else
{
$_SESSION['no_dp_change'] = 'Error in updating Profile picture!';
header("location:ca-profile.php");
}
}
?>