oops
[phpmyadmin/crack.git] / ldi_check.php3
blob89898976d89ae0f28f8cf8aa46b91b550450973a
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * This file checks and builds the sql-string for
8 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name
9 * [FIELDS
10 * [TERMINATED BY '\t']
11 * [OPTIONALLY] ENCLOSED BY "]
12 * [ESCAPED BY '\\' ]]
13 * [LINES TERMINATED BY '\n']
14 * [(column_name,...)]
18 /**
19 * Gets some core scripts
21 require('./libraries/grab_globals.lib.php3');
22 require('./libraries/common.lib.php3');
25 /**
26 * The form used to define the query has been submitted -> do the work
28 if (isset($btnLDI) && ($textfile != 'none')) {
29 if (!isset($replace)) {
30 $replace = '';
33 error_reporting(E_ALL);
34 chmod($textfile, 0644);
36 // Kanji encoding convert appended by Y.Kawada
37 if (function_exists('PMA_kanji_file_conv')) {
38 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : '');
41 // Convert the file's charset if necessary
42 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
43 && isset($charset_of_file) && $charset_of_file != $charset) {
44 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile);
47 // Formats the data posted to this script
48 $textfile = PMA_sqlAddslashes($textfile);
49 if (get_magic_quotes_gpc()) {
50 $field_terminater = stripslashes($field_terminater);
51 $enclosed = PMA_sqlAddslashes(stripslashes($enclosed));
52 $escaped = PMA_sqlAddslashes(stripslashes($escaped));
53 $line_terminator = stripslashes($line_terminator);
54 $column_name = PMA_sqlAddslashes(stripslashes($column_name));
55 } else {
56 $enclosed = PMA_sqlAddslashes($enclosed);
57 $escaped = PMA_sqlAddslashes($escaped);
58 $column_name = PMA_sqlAddslashes($column_name);
61 // (try to) make sure the file is readable:
62 chmod($textfile, 0777);
64 // Builds the query
65 $query = 'LOAD DATA';
67 // for versions before 3.23.49, we use the LOCAL keyword, because
68 // there was a version (cannot find which one, and it does not work
69 // with 3.23.38) where the user can LOAD, even if the user does not
70 // have FILE priv, and even if the file is on the server
71 // (which is the present case)
73 // if we find how to check the server about --local-infile
74 // and --enable-local-infile, we could modify the code
75 // to use LOCAL for version >= 32349 if the server accepts it
77 // we could also code our own loader, but LOAD DATA INFILE is optimized
78 // for speed
80 if (PMA_MYSQL_INT_VERSION < 32349) {
81 $query .= ' LOCAL';
83 $query .= ' INFILE \'' . $textfile . '\'';
84 if (!empty($replace)) {
85 $query .= ' ' . $replace;
87 $query .= ' INTO TABLE ' . PMA_backquote($into_table);
88 if (isset($field_terminater)) {
89 $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
91 if (isset($enclose_option) && strlen($enclose_option) > 0) {
92 $query .= ' OPTIONALLY';
94 if (strlen($enclosed) > 0) {
95 $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
97 if (strlen($escaped) > 0) {
98 $query .= ' ESCAPED BY \'' . $escaped . '\'';
100 if (strlen($line_terminator) > 0){
101 $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
103 if (strlen($column_name) > 0) {
104 if (PMA_MYSQL_INT_VERSION >= 32306) {
105 $query .= ' (';
106 $tmp = split(',( ?)', $column_name);
107 for ($i = 0; $i < count($tmp); $i++) {
108 if ($i > 0) {
109 $query .= ', ';
111 $query .= PMA_backquote(trim($tmp[$i]));
112 } // end for
113 $query .= ')';
114 } else {
115 $query .= ' (' . $column_name . ')';
119 // Executes the query
120 // sql.php3 will stripslash the query if 'magic_quotes_gpc' is set to on
121 if (get_magic_quotes_gpc()) {
122 $sql_query = addslashes($query);
123 } else {
124 $sql_query = $query;
127 // We could rename the ldi* scripts to tbl_properties_ldi* to improve
128 // consistency with the other sub-pages.
130 // The $goto in ldi_table.php3 is set to tbl_properties.php3 but maybe
131 // if would be better to Browse the latest inserted data.
132 include('./sql.php3');
137 * The form used to define the query hasn't been yet submitted -> loads it
139 else {
140 include('./ldi_table.php3');