updates
[phpmyadmin/crack.git] / ldi_check.php3
blob1171ff0b6b6910b00c3533d8b5e6aef3b580ec18
1 <?php
2 /* $Id$ */
5 /**
6 * This file checks and builds the sql-string for
7 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name
8 * [FIELDS
9 * [TERMINATED BY '\t']
10 * [OPTIONALLY] ENCLOSED BY "]
11 * [ESCAPED BY '\\' ]]
12 * [LINES TERMINATED BY '\n']
13 * [(column_name,...)]
17 /**
18 * Gets some core scripts
20 require('./libraries/grab_globals.lib.php3');
21 require('./libraries/common.lib.php3');
24 /**
25 * The form used to define the query has been submitted -> do the work
27 if (isset($btnLDI) && ($textfile != 'none')) {
28 if (!isset($replace)) {
29 $replace = '';
32 error_reporting(E_ALL);
33 chmod($textfile, 0644);
35 // Kanji encoding convert appended by Y.Kawada
36 if (function_exists('PMA_kanji_file_conv')) {
37 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : '');
40 // Convert the file's charset if necessary
41 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
42 && isset($charset_of_file) && $charset_of_file != $charset) {
43 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile);
46 // Formats the data posted to this script
47 $textfile = PMA_sqlAddslashes($textfile);
48 if (get_magic_quotes_gpc()) {
49 $field_terminater = stripslashes($field_terminater);
50 $enclosed = PMA_sqlAddslashes(stripslashes($enclosed));
51 $escaped = PMA_sqlAddslashes(stripslashes($escaped));
52 $line_terminator = stripslashes($line_terminator);
53 $column_name = PMA_sqlAddslashes(stripslashes($column_name));
54 } else {
55 $enclosed = PMA_sqlAddslashes($enclosed);
56 $escaped = PMA_sqlAddslashes($escaped);
57 $column_name = PMA_sqlAddslashes($column_name);
60 // Builds the query
61 $query = 'LOAD DATA LOCAL INFILE \'' . $textfile . '\'';
62 if (!empty($replace)) {
63 $query .= ' ' . $replace;
65 $query .= ' INTO TABLE ' . PMA_backquote($into_table);
66 if (isset($field_terminater)) {
67 $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
69 if (isset($enclose_option) && strlen($enclose_option) > 0) {
70 $query .= ' OPTIONALLY';
72 if (strlen($enclosed) > 0) {
73 $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
75 if (strlen($escaped) > 0) {
76 $query .= ' ESCAPED BY \'' . $escaped . '\'';
78 if (strlen($line_terminator) > 0){
79 $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
81 if (strlen($column_name) > 0) {
82 if (PMA_MYSQL_INT_VERSION >= 32306) {
83 $query .= ' (';
84 $tmp = split(',( ?)', $column_name);
85 for ($i = 0; $i < count($tmp); $i++) {
86 if ($i > 0) {
87 $query .= ', ';
89 $query .= PMA_backquote(trim($tmp[$i]));
90 } // end for
91 $query .= ')';
92 } else {
93 $query .= ' (' . $column_name . ')';
97 // Executes the query
98 // sql.php3 will stripslash the query if 'magic_quotes_gpc' is set to on
99 if (get_magic_quotes_gpc()) {
100 $sql_query = addslashes($query);
101 } else {
102 $sql_query = $query;
105 // Set an empty sub_part to avoid an undefined variable.
106 // We could also rename the ldi* scripts
107 // to tbl_properties_ldi* to improve consistency with the other sub-pages.
109 // The $goto in ldi_table.php3 is set to tbl_properties.php3 but maybe
110 // if would be better to Browse the latest inserted data.
111 $sub_part = '';
112 include('./sql.php3');
117 * The form used to define the query hasn't been yet submitted -> loads it
119 else {
120 include('./ldi_table.php3');