-
Notifications
You must be signed in to change notification settings - Fork 0
/
askquest.php
102 lines (83 loc) · 2.2 KB
/
askquest.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
<?php
include_once('class.php');
$val = $ob->loggedin();
if($val == false)
{
header('location:main.php');
}
else
{
$id = $_SESSION['user_id'];
}
$quest = $_POST['quest'];
$location='./uploads/'.$id.'/';
if(isset($_FILES["file"]["name"]) and !empty($_FILES["file"]["name"]))
{
$valid_extension = array("jpeg","png","jpg");
$temp = explode(".",$_FILES["file"]["name"]);
$file_extension = end($temp);
if((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg")) && ($_FILES["file"]["size"] < 2000000))
{
$ext = $_FILES["file"]["type"];
if($_FILES["file"]["error"]>0)
{
echo "Return Code: ".$_FILES["file"]["error"]."<br/><br/>";
}
else
{
if(file_exists($location.$_FILES["file"]["name"]))
{
echo '<span style="color:red">'.$_FILES["file"]["name"]." already exists</span>";
}
else
{
$name = md5(time());
$source = $_FILES["file"]["tmp_name"];
$target = $location.$name;
move_uploaded_file($source,$target);
$ob->ask_to_pioneer_with_pic($id,$quest,$target);
//---------------------------------------------
if($ext == "image/jpeg" || $ext == "image/jpg"){
$src = imagecreatefromjpeg($target);
}
else if($ext == "image/png"){
$src = imagecreatefrompng($target);
}
list($width,$height)=getimagesize($target);
$newwidth="";
$newheight="";
$ratio = $width/$height;
if($width/$height > 1.163)
{
//if($height>=430)
$newheight = 400;
$newwidth = round($newheight*$ratio);
}
else{
//if($width>=500)
$newwidth = 500;
$newheight = round($newwidth/$ratio);
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
/*$to_crop_array = array('x' =>0 , 'y' => 0, 'width' => $newwidth, 'height'=> $newheight);
$thumb_im = imagecrop($src, $to_crop_array);
*/
$filename = $target;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
//---------------------------------------------
}
}
}
else
{
echo '<span style="color:red;" class="alert">Only jpeg/jpg files are allowed and size should be less than 2 Mb</span>';
}
}
else
{
$ob->ask_to_pioneer($id,$quest);
}
?>