Another mechanism against stupid people who use the translator list as a list of...
[phpmyadmin/crack.git] / ldi_check.php3
blob87b3b5186aebe3a2daabad730b5d48bb600def35
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 $enclosed = PMA_sqlAddslashes($enclosed);
50 $escaped = PMA_sqlAddslashes($escaped);
51 $column_name = PMA_sqlAddslashes($column_name);
53 // (try to) make sure the file is readable:
54 chmod($textfile, 0777);
56 // Builds the query
57 $query = 'LOAD DATA';
59 // for versions before 3.23.49, we use the LOCAL keyword, because
60 // there was a version (cannot find which one, and it does not work
61 // with 3.23.38) where the user can LOAD, even if the user does not
62 // have FILE priv, and even if the file is on the server
63 // (which is the present case)
65 // we could also code our own loader, but LOAD DATA INFILE is optimized
66 // for speed
68 if (PMA_MYSQL_INT_VERSION < 32349) {
69 $query .= ' LOCAL';
72 if (PMA_MYSQL_INT_VERSION > 40003) {
73 $tmp_query = "SHOW VARIABLES LIKE 'local\\_infile'";
74 $result = PMA_mysql_query($tmp_query);
75 if ($result != FALSE && mysql_num_rows($result) > 0) {
76 $tmp = PMA_mysql_fetch_row($result);
77 if ($tmp[1] == 'ON') {
78 $query .= ' LOCAL';
81 mysql_free_result($result);
84 $query .= ' INFILE \'' . $textfile . '\'';
85 if (!empty($replace)) {
86 $query .= ' ' . $replace;
88 $query .= ' INTO TABLE ' . PMA_backquote($into_table);
89 if (isset($field_terminater)) {
90 $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
92 if (isset($enclose_option) && strlen($enclose_option) > 0) {
93 $query .= ' OPTIONALLY';
95 if (strlen($enclosed) > 0) {
96 $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
98 if (strlen($escaped) > 0) {
99 $query .= ' ESCAPED BY \'' . $escaped . '\'';
101 if (strlen($line_terminator) > 0){
102 $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
104 if (strlen($column_name) > 0) {
105 if (PMA_MYSQL_INT_VERSION >= 32306) {
106 $query .= ' (';
107 $tmp = split(',( ?)', $column_name);
108 for ($i = 0; $i < count($tmp); $i++) {
109 if ($i > 0) {
110 $query .= ', ';
112 $query .= PMA_backquote(trim($tmp[$i]));
113 } // end for
114 $query .= ')';
115 } else {
116 $query .= ' (' . $column_name . ')';
120 // We could rename the ldi* scripts to tbl_properties_ldi* to improve
121 // consistency with the other sub-pages.
123 // The $goto in ldi_table.php3 is set to tbl_properties.php3 but maybe
124 // if would be better to Browse the latest inserted data.
125 include('./sql.php3');
130 * The form used to define the query hasn't been yet submitted -> loads it
132 else {
133 include('./ldi_table.php3');