-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocial_photo.php
More file actions
134 lines (88 loc) · 2.55 KB
/
social_photo.php
File metadata and controls
134 lines (88 loc) · 2.55 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
include( 'includes/database.php' );
include( 'includes/config.php' );
include( 'includes/functions.php' );
secure();
include( 'includes/header.php' );
if( !isset( $_GET['id'] ) )
{
header( 'Location: social.php' );
die();
}
if( isset( $_FILES['photo'] ) )
{
if( $_FILES['photo']['error'] == 0 )
{
switch( $_FILES['photo']['type'] )
{
case 'image/png':
$type = 'png';
break;
case 'image/jpg':
case 'image/jpeg':
$type = 'jpeg';
break;
case 'image/gif':
$type = 'gif';
break;
}
$query = 'UPDATE social SET
photo = "data:image/'.$type.';base64,'.base64_encode( file_get_contents( $_FILES['photo']['tmp_name'] ) ).'"
WHERE id = '.$_GET['id'].'
LIMIT 1';
mysqli_query( $connect, $query );
set_message( 'Social photo has been updated' );
}
header( 'Location: social.php' );
die();
}
if( isset( $_GET['id'] ) )
{
if( isset( $_GET['delete'] ) )
{
$query = 'UPDATE social SET
photo = ""
WHERE id = '.$_GET['id'].'
LIMIT 1';
$result = mysqli_query( $connect, $query );
set_message( 'Social photo has been deleted' );
header( 'Location: social.php' );
die();
}
$query = 'SELECT *
FROM social
WHERE id = '.$_GET['id'].'
LIMIT 1';
$result = mysqli_query( $connect, $query );
if( !mysqli_num_rows( $result ) )
{
header( 'Location: social.php' );
die();
}
$record = mysqli_fetch_assoc( $result );
}
include 'includes/wideimage/WideImage.php';
?>
<h2>Edit Social</h2>
<p>
Note: For best results, photos should be approximately 400 x 400 pixels.
</p>
<?php if( $record['photo'] ): ?>
<?php
$data = base64_decode( explode( ',', $record['photo'] )[1] );
$img = WideImage::loadFromString( $data );
$data = $img->resize( 200, 200, 'outside' )->crop( 'center', 'center', 200, 200 )->asString( 'jpg', 70 );
?>
<p><img src="data:image/jpg;base64,<?php echo base64_encode( $data ); ?>" width="200" height="200"></p>
<p><a href="social_photo.php?id=<?php echo $_GET['id']; ?>&delete"><i class="fas fa-trash-alt"></i> Delete this Photo</a></p>
<?php endif; ?>
<form method="post" enctype="multipart/form-data">
<label for="photo">Photo:</label>
<input type="file" name="photo" id="photo">
<br>
<input type="submit" value="Save Photo">
</form>
<p><a href="social.php"><i class="fas fa-arrow-circle-left"></i> Return to Team List</a></p>
<?php
include( 'includes/footer.php' );
?>