-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-new-group-save.php
executable file
·104 lines (83 loc) · 3.71 KB
/
add-new-group-save.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
//e_reporting("ALL");
include("config/connection.php");
include("imageresize/smart_resize_image.function.php");
session_start();
$conn=new connections();
$conn=$conn->connect();
if(isset($_SESSION['logged_user_id']) && !empty($_SESSION['logged_user_id']))
{
/*
echo "<br><pre>";
print_r($_FILES);echo "<br>";
print_r($_REQUEST);
echo "</pre><br>";
die();
*/
if(isset($_REQUEST['submit']))
{
$group_name = isset($_REQUEST['group_name'])?$_REQUEST['group_name']:'';
$description = isset($_REQUEST['description'])?$_REQUEST['description']:'';
$currentDate = date('Y-m-d');
$uploaded_file = '';
$descriptions = mysqli_real_escape_string($conn,$description);
$group_names = mysqli_real_escape_string($conn,$group_name);
$sql="insert into groups (group_name,description,image,created_by_id,created_by_user_role,created_date) values ('".$group_names."','".$descriptions."', '".$uploaded_file."','".$_SESSION['logged_user_id']."','".$_SESSION['logged_role_code']."', '".$currentDate."')" ;//echo $ssql;exit();
//die("test3 ");
$tableResult = mysqli_query($conn, $sql);
$MSG = "Registered Sucessfully!";
$result['success'] = 1;
$result['error'] = 0;
$result['MSG'].="<br>".$MSG;
if($tableResult > 0)
{
$group_last_id = mysqli_insert_id($conn);
$uploaded_file = '';
if(isset($_FILES) && is_array($_FILES))
{
// die("test");
$target_dir = "images/groupPhotos/";
$target_file = $target_dir .time(). basename($_FILES['file']["name"]);
//die($target_file);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$target_file = $target_dir .$group_last_id.'.'.$imageFileType ;
//indicate which file to resize (can be any type jpg/png/gif/etc...)
$file = $_FILES['file']["tmp_name"];//'your_path_to_file/file.png';
//indicate the path and name for the new resized file
$resizedFile = $target_file;//'your_path_to_file/resizedFile.png';
//call the function (when passing path to pic)
if (smart_resize_image($file , null, "200" , "200" , false , $resizedFile , false , false ,100 )){
$sqlUpdate="update groups set image='".$group_last_id.'.'.$imageFileType."' where group_id=".$group_last_id;
$tableResults = mysqli_query($conn, $sqlUpdate);
if($tableResults > 0)
{
$uploaded_file= $group_last_id.'.'.$imageFileType;
$result['msg'] = "The file ".$group_last_id.'.'.$imageFileType. " has been uploaded.";
$result['imageName'] = 'groupPhotos/'.$group_last_id.'.'.$imageFileType;
$passStr = $group_names.'-Group Created.<br>Redirecting....';
$passImg = 'groupPhotos/'.$group_last_id.'.'.$imageFileType;
header("location:well-come.php?passStr=$passStr&passImg=$passImg&redirect=my-group");
//header("Refresh: 3; url=my-group.php");
//echo '<center><h1 style="color:red">'.$group_names.'-Group Created .Redirecting....</h1></center>';
}
} else {
$passStr = 'Sorry, there was an error uploading your file.';
$passImg = 'groupPhotos/img-3.jpg';
header("location:well-come.php?passStr=$passStr&passImg=$passImg&redirect=add-new-group");
}
}
//echo json_encode($result);
//die();
}
}
//print_r($tableResult);die();
//}
}//session checking
else
{
$passStr = 'You are not authorized.Redirecting....';
$passImg = 'groupPhotos/img-3.jpg';
header("location:well-come.php?passStr=$passStr&passImg=$passImg&redirect=index");
}
?>