-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEdit_File_Info_Example.php
More file actions
265 lines (205 loc) · 12 KB
/
Edit_File_Info_Example.php
File metadata and controls
265 lines (205 loc) · 12 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--***************************************************************************
*
* Filename: Edit_File_Info_Example.php
*
* Description: An example file showing how edit_file_info allows the user to edit
* the metadata of an image over the internet in the same way
* that Photoshop edits 'File Info' data
*
* Author: Evan Hunter
*
* Date: 17/11/2004
*
* Project: PHP JPEG Metadata Toolkit
*
* Revision: 1.12
*
* Changes: 1.10 -> 1.11 : Changed displayed toolkit version numbers to reference Toolkit_Version.php
* 1.11 -> 1.12 : Added parsing of filename to prevent attacks, changed to use _GET variable
*
* URL: http://electronics.ozhiker.com
*
* Copyright: Copyright Evan Hunter 2004
*
* License: This file is part of the PHP JPEG Metadata Toolkit.
*
* The PHP JPEG Metadata Toolkit 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 2 of the License, or (at your
* option) any later version.
*
* The PHP JPEG Metadata Toolkit 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 the PHP JPEG Metadata Toolkit; if not,
* write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* If you require a different license for commercial or other
* purposes, please contact the author: evan@ozhiker.com
*
***************************************************************************-->
<head>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<style type="text/css" media="screen, print, projection">
<!--
BODY { background-color:#505050; color:#F0F0F0 }
a { color:orange }
.EXIF_Main_Heading { color:red }
.EXIF_Secondary_Heading{ color: orange}
.EXIF_Table { border-collapse: collapse ; border: 1px solid #909000}
.EXIF_Table tbody td{border-width: 1px; border-style:solid; border-color: #909000;}
-->
</style>
<?php
// Turn off Error Reporting
error_reporting ( 0 );
include 'Toolkit_Version.php'; // Change: added as of version 1.11
// Retrieve the JPEG image filename from the http url request
if ( ( !array_key_exists( 'jpeg_fname', $_GET ) ) ||
( $_GET['jpeg_fname'] == "" ) )
{
echo "<title>No image filename defined</title>\n";
echo "</head>\n";
echo "<body>\n";
echo "<p>No image filename defined - use GET method with field: jpeg_fname</p>\n";
echo "<p><a href=\"http://www.ozhiker.com/electronics/pjmt/\" >PHP JPEG Metadata Toolkit version " . $GLOBALS['Toolkit_Version'] . ", Copyright (C) 2004 Evan Hunter</a></p>\n"; // Change: displayed toolkit version numbers to reference Toolkit_Version.php - as of version 1.11
echo "</body>\n";
exit( );
}
else
{
$filename = $_GET['jpeg_fname'];
// Sanitize the filename to remove any hack attempts
if ( 0 == preg_match ( '/^\.?\/?([_A-Za-z0-9]+\.jpe?g)$/i', $filename ) )
{
echo "<title>Bad image filename defined</title>\n";
echo "</head>\n";
echo "<body>\n";
echo "<p>Bad image filename defined - Must be jpg or jpeg</p>\n";
echo "<p><a href=\"http://www.ozhiker.com/electronics/pjmt/\" >PHP JPEG Metadata Toolkit version " . $GLOBALS['Toolkit_Version'] . ", Copyright (C) 2004 Evan Hunter</a></p>\n"; // Change: displayed toolkit version numbers to reference Toolkit_Version.php - as of version 1.11
echo "</body>\n";
exit( );
}
}
?>
<title>Edit Photoshop File Info details for <?php $filename ?></title>
</head>
<body >
<div>
<p>Powered by: <a href="http://www.ozhiker.com/electronics/pjmt/" >PHP JPEG Metadata Toolkit version <?php echo $GLOBALS['Toolkit_Version'] ?>, Copyright (C) 2004 Evan Hunter</a></p> <!-- Change: displayed toolkit version numbers to reference Toolkit_Version.php - as of version 1.11 -->
<br/>
<br/>
<?php
// Output a heading
echo "<H1>Edit Photoshop File Info details for $filename</H1>";
// Output a link to display the full metadata
echo "<p><a href=\"Example.php?jpeg_fname=" . $filename . "\" >View Full Metatdata Information</a></p>\n";
// Display a small copy of the image
echo "<p><img src=\"$filename\" height=\"50%\"></p>";
// Define defaults for the fields - These are only used where the image has blank fields
$default_ps_file_info_array = array (
'title' => "",
'author' => "Evan Hunter",
'authorsposition' => "",
'caption' => "",
'captionwriter' => "Evan Hunter",
'jobname' => "",
'copyrightstatus' => "Copyrighted Work",
'copyrightnotice' => "Copyright (c) Evan Hunter 2004",
'ownerurl' => "http://www.ozhiker.com",
'keywords' => array(),
'category' => "",
'supplementalcategories'=> array(),
'date' => "",
'city' => "",
'state' => "Tasmania",
'country' => "Australia",
'credit' => "Evan Hunter",
'source' => "Evan Hunter",
'headline' => "",
'instructions' => "",
'transmissionreference' => "",
'urgency' => ""
);
// outputfilename must always be defined, as it specifies the
// file which will be changed
// These two lines create a temporary copy of the file
// which will be the one that is edited, keeping
// the original intact. - This would not be required if you wanted
// to change the original - in that case just set $outputfilename = $filename
$outputfilename = get_next_filename( );
copy( $filename, $outputfilename );
// Include the File Info Editor.
include "Edit_File_Info.php";
?>
</div>
</body>
</html>
<?php
/******************************************************************************
*
* Function: get_next_filename
*
* Description: Simple function to cycle through temporary filenames ( a to z )
* This means that there will only be a maximum of 26 temporary files,
* hence avoiding filling up the server or having a cron job to remove them.
*
* NOTE: This function would not normally be required, and is just
* to protect my website (and others) from filling up with
* temporary files whilst demonstrating the toolkit
*
* Parameters: none
*
* Returns: TRUE - on Success
* FALSE - on Failure
*
******************************************************************************/
function get_next_filename( )
{
// Read the letter of the next temp file from disk
$filename = file( "next_temp_file.dat" );
// If it wasn't read - start at 'a'
if ( $filename == FALSE )
{
$filename = 'a';
}
else
{
$filename = $filename{0};
}
// Ensure the filename letter is valid
if ( ( $filename < 'a' ) || ( $filename > 'z' ) )
{
$filename = 'a';
}
// Check if the names are up to 'z'
if( $filename == 'z' )
{
// Name is at z - the next one should be 'a'
$new_filename = 'a';
}
else
{
// The name is not 'z' add one to it to get the next value
$new_filename = chr( ord( $filename ) + 1 );
}
// Write the next temp file letter back into the file
$Fhnd = fopen ("next_temp_file.dat", "w");
fwrite ($Fhnd, $new_filename);
fclose ($Fhnd);
// return the filename
return "temp_$filename.jpg";
}
/******************************************************************************
* End of Function: get_next_filename
******************************************************************************/
?>