-
Notifications
You must be signed in to change notification settings - Fork 0
/
photoupload.php
242 lines (198 loc) · 5.59 KB
/
photoupload.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
/* !--
JuMiMeal - Anymeal Web Frontend
by Michael Pilgermann (kichkasch@gmx.de)
Copyright (C) 2008 Michael Pilgermann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
The purpose of this PHP-Script is simply accessing a database, which contains recipe information
for reading purposes only in order to display them in a web browser. The accessed database must
be in the design given by the Anymeal (http://www.wedesoft.demon.co.uk/anymeal-api/) application.
This application will propably also be used for adding and modifying content in the database as
this web frontend is not capable of supporting this.
-->
*/
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta name="Description" content="Web Frontend for Anymeal database" />
<meta name="Keywords" content="" />
<meta name="Copyright" content="Michael Pilgermann" />
<meta name="Designed By" content="www.kichkasch.de" />
<meta name="Language" content="English" />
<title>[ADMIN] JuMiMeal Photo Admin</title>
<!-- All Images Created And Copyrighted By Christina Chun Unless Noted Otherwise. All rights Reserved. -->
<link rel="stylesheet" type="text/css" href="default.css"/>
</head>
<?php
/*
Processing / Initializing
*/
include 'config.php';
include 'photomenu.php';
include 'tools.php';
/* !--
END processing
*/
?>
<body>
<div class="main">
<div class="container">
<?php printMenu(); ?>
<div class="content">
<?php saveFile(); ?>
<?php deleteFiles(); ?>
<div class="item">
<table cellpadding="10" cellspacing="10" border="0" width="100%">
<tr>
<td width="10%"> </td>
<td width="50%" align="left" valign="top">
<form action="photoupload.php" method="post" enctype="multipart/form-data">
<p><h1>Upload new photo</h1><br/>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /></p>
</td>
<td align="right" valign="middle">
<input type="submit" name="submit" value="Upload" />
</td>
</form>
<td width="10%"> </td>
</tr>
</table>
</div>
<div class="item">
<table cellpadding="10" cellspacing="10" border="0" width="100%">
<tr>
<td width="10%"> </td>
<td width="80%">
<p><h1>Available photos</h1></p>
<table cellpadding="5" cellspacing="5" border="0" align="center" valign="top">
<form action="photoupload.php" method="post" enctype="multipart/form-data">
<?php
$path = "/var/www/anymeal/photos";
$jpgs = directoryToArray($path);
$i=0;
foreach ($jpgs as $jpeg)
{
if ($i % 4 == 0)
{
echo "<tr>";
}
echo '<td width="33%" align="center" valign="middle">';
print('<p><a href="photos/' . $jpeg . '"><img src="photos/' . $jpeg . '" width="90" border="0" alt=""></a><br>');
print ('<input type="checkbox" name="deletecandidates[]" value="'. $jpeg . '">' . $jpeg . '</p>');
echo "</td>";
if (($i+1) % 4 == 0)
{
echo "</tr>";
}
$i = $i + 1;
} /* foreach */
?>
<tr><td> </td><td> </td><td colspan="2" align="right"><input type="submit" name="submit" value="Delete selected" /></td></tr>
</form>
</table>
</td>
<td width="10%"> </td>
</tr>
</table>
</div>
</div>
<?php printFooter(); ?>
</div>
</div>
</body>
</html>
<?php
/*
Pages and subpages
*/
/* Nicked from http://www.w3schools.com/PHP/php_file_upload.asp */
function saveFile()
{
if ($_FILES["file"])
{
?>
<div class="item">
<table cellpadding="10" cellspacing="10" border="0" width="100%">
<tr>
<td width="10%"> </td>
<td width="80%">
<p><h1>Feedback from last upload:</h1><br/>
<?php
if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("photos/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"photos/" . $_FILES["file"]["name"]);
echo "Stored in: " . "photos/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
</td>
<td width="10%"> </td>
</tr>
</table>
</div>
<?php
} /* if */
} /* function */
function deleteFiles()
{
if (isset($_REQUEST['deletecandidates']) )
{
$deletes = $_REQUEST['deletecandidates'];
?>
<div class="item">
<table cellpadding="10" cellspacing="10" border="0" width="100%">
<tr>
<td width="10%"> </td>
<td width="80%">
<p><h1>Feedback from last delete:</h1><br/>
<?php
foreach ($deletes as $delete)
{
$delete = "photos/" . $delete;
print ("Deleting: " . $delete . "<br/>");
unlink ($delete) or print ('Unable to delete <' . $delete . '>');
}
?>
</td>
<td width="10%"> </td>
</tr>
</table>
</div>
<?php
} /* if */
} /* function */
?>