-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent-profile-upload.php
executable file
·59 lines (52 loc) · 1.83 KB
/
student-profile-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
<?php
include 'connection.php';
session_start();
$role = $_SESSION['sess_userrole'];
$email = $_SESSION['sess_email'];
if(!isset($email) || $role!="student"){
header('Location: index.php?err=2');
}
$sql = "SELECT * FROM student WHERE email = '$email'";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($query);
if(isset($_POST['submit'])){
$student_id = $row["student_id"];
$file_name = rand(1000, 10000)."-".$_FILES['profile']['name'];
//$new_file_name = $strtolower($file_name);
$final_name = str_replace(' ', '-', $file_name);
$file_ext = explode('.', $file_name);
$file_error = $_FILES['profile']['error'];
$allowed = array('png', 'jpg', 'jpeg');
$temp_name = $_FILES['profile']['tmp_name'];
if($file_error === 0){
if(isset($file_name) && !empty($file_name)){
$location = "img/student/";
if(move_uploaded_file($temp_name, $location.$final_name)){
echo "File moved";
$query = "INSERT INTO student_profile (student_id, email, picture) VALUES ('$student_id', '$email', '$final_name')";
mysqli_query($conn, $query);
$success = $_SESSION['success'];
header("Location: student-dashboard.php?success");
exit();
?>
<?php
}else{
echo "Umechema";
?>
<?php
}
}else{
echo "File name error";
}
}else{
echo "Hola";
?>
<!-- <script>-->
<!-- window.location.href='student-dashboard.php?failed';-->
<!-- //alert('successfully uploaded');-->
<!-- </script>-->
<?php
}
}else{
echo "Form didnt work";
}