3 // vim: expandtab sw=4 ts=4 sts=4:
5 // note: grab_globals has extracted the fields from _FILES
8 // f i e l d u p l o a d e d f r o m a f i l e
10 // garvin: original if-clause checked, whether input was stored in a possible fields_upload_XX var.
11 // Now check, if the field is set. If it is empty or a malicious file, do not alter fields contents.
12 // If an empty or invalid file is specified, the binary data gets deleter. Maybe a nice
13 // new text-variable is appropriate to document this behaviour.
15 // garvin: security cautions! You could trick the form and submit any file the webserver has access to
16 // for upload to a binary field. Shouldn't be that easy! ;)
18 // garvin: default is to advance to the field-value parsing. Will only be set to true when a
19 // binary file is uploaded, thus bypassing further manipulation of $val.
22 if (isset($
{"fields_upload_" . $key}) && $
{"fields_upload_" . $key} != 'none'){
23 // garvin: This fields content is a blob-file upload.
25 if (!empty($
{"fields_upload_" . $key})) {
26 // garvin: The blob-field is not empty. Check what we have there.
28 $data_file = $
{"fields_upload_" . $key};
30 if (is_uploaded_file($data_file)) {
31 // garvin: A valid uploaded file is found. Look into the file...
33 $val = fread(fopen($data_file, "rb"), filesize($data_file));
34 // nijel: This is probably the best way how to put binary data
35 // into MySQL and it also allow not to care about charset
36 // conversion that would otherwise corrupt the data.
39 // garvin: The upload was valid. Check in new blob-field's contents.
40 $val = '0x' . bin2hex($val);
44 // garvin: ELSE: an empty file was uploaded. Remove blob-field's contents.
45 // Blob-fields are preserved, see below. ($protected$)
48 // garvin: Danger, will robinson. File is malicious. Blob-fields are preserved, see below. ($protected$)
53 // garvin: else: Post-field contains no data. Blob-fields are preserved, see below. ($protected$)
58 // f i e l d v a l u e i n t h e f o r m
59 if (isset($fields_type[$key])) $type = $fields_type[$key];
61 switch (strtolower($val)) {
67 // if we have an enum, then construct the value
68 $f = 'field_' . md5($key);
70 $val = implode(',', $
$f);
74 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
81 // if we have a set, then construct the value
82 $f = 'field_' . md5($key);
84 $val = implode(',', $
$f);
85 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
91 // if we have a foreign key, then construct the value
92 $f = 'field_' . md5($key);
94 $val = implode(',', $
$f);
98 $val = "'" . PMA_sqlAddslashes(urldecode($val)) . "'";
105 // here we are in protected mode (asked in the config)
106 // so tbl_change has put this special value in the
107 // fields array, so we do not change the field value
108 // but we can still handle field upload
110 // garvin: when in UPDATE mode, do not alter field's contents. When in INSERT
111 // mode, insert empty field because no values were submitted.
112 if (isset($fieldlist)) {
120 $val = "'" . PMA_sqlAddslashes($val) . "'";
125 $val = "'" . PMA_sqlAddslashes($val) . "'";
129 // Was the Null checkbox checked for this field?
130 // (if there is a value, we ignore the Null checkbox: this could
131 // be possible if Javascript is disabled in the browser)
132 if (isset($fields_null) && isset($fields_null[$encoded_key])
136 } // end else (field value in the form)