-
Notifications
You must be signed in to change notification settings - Fork 0
/
postuploadphoto.php
54 lines (49 loc) · 1.88 KB
/
postuploadphoto.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
<?php
require 'required.php';
/*retrieving current photo*/
$query = "select `photo` from `login` where `L_id` = '$l_id'";
if($query_run = mysql_query($query)) {
$current_photo = mysql_result($query_run, 0, 'photo');
} else {
echo mysql_error();
}
/*code to upload the given photo*/
if(isset($_FILES['photo'])) {
$name = $_FILES['photo']['name'];
$tmp_name = $_FILES['photo']['tmp_name'];
$size = $_FILES['photo']['size'];
$type = $_FILES['photo']['type'];
$extension = strtolower(substr($name, strpos($name, '.') + 1));
$max = 1000000; //2MB
if(!empty($name)) {
if($size <= $max && ($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') &&
($type == 'image/jpeg' || $type == 'image/png')) {
if(move_uploaded_file($tmp_name, $image_folder.$name)) {
/*query to store image name in database*/
$query = "update `login` set `photo` = '$name' where `L_id` = '$l_id'";
if(!($query_run = mysql_query($query))) {
echo mysql_error();
} else {
/*code to delete previous photo*/
if(!empty($current_photo))
unlink($image_folder.$current_photo);
echo '<script type=text/javascript> window.location.href = "personal.php"; </script>';
}
} else {
echo 'not successful';
}
} else if($size> $max)
echo '<script type=text/javascript> window.location.href = "uploadphoto.php?error=2"; </script>';
else
echo '<script type=text/javascript> window.location.href = "uploadphoto.php?error=3"; </script>';
} else {
echo '<script type=text/javascript> window.location.href = "uploadphoto.php?error=1"; </script>';
}
} else if(isset($_GET['rem'])) { //code to remove photo
$query = "update login set photo = '' where L_id = '$l_id'";
if(!mysql_query($query))
echo mysql_error();
else
echo '<script type=text/javascript> window.location.href = "personal.php"; </script>';
}
?>