-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticles_photo.php
More file actions
139 lines (91 loc) · 2.64 KB
/
articles_photo.php
File metadata and controls
139 lines (91 loc) · 2.64 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
135
136
137
138
139
<?php
include( 'includes/database.php' );
include( 'includes/config.php' );
include( 'includes/functions.php' );
secure();
include( 'includes/header.php' );
if( !isset( $_GET['id'] ) )
{
header( 'Location: articles.php' );
die();
}
if( isset( $_FILES['photo'] ) )
{
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 articles 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( 'Article photo has been updated' );
header( 'Location: articles.php' );
die();
}
if( isset( $_GET['id'] ) )
{
if( isset( $_GET['delete'] ) )
{
$query = 'UPDATE articles SET
photo = ""
WHERE id = '.$_GET['id'].'
LIMIT 1';
$result = mysqli_query( $connect, $query );
set_message( 'Article photo has been deleted' );
header( 'Location: articles.php' );
die();
}
$query = 'SELECT *
FROM articles
WHERE id = '.$_GET['id'].'
LIMIT 1';
$result = mysqli_query( $connect, $query );
if( !mysqli_num_rows( $result ) )
{
header( 'Location: articles.php' );
die();
}
$record = mysqli_fetch_assoc( $result );
}
include 'includes/wideimage/WideImage.php';
?>
<h2>Edit Article</h2>
<p>
Note: For best results, photos should be approximately 800 x 800 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="articles_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="articles.php"><i class="fas fa-arrow-circle-left"></i> Return to Article List</a></p>
<?php
include( 'includes/footer.php' );
?>