Error Buddy
Do you have an error message from your application? Then find the answer with Error Buddy. You can search over 40000 source code files and troubleshooting documents using our beta lucene/nutch search interface or if you prefer, search as normal using google. With LXR technology you can drill right down into the line of source code where it came from with full cross-referencing.
If after searching you didn't get your ideal answer, or you are still unclear what the error means, you can choose to post that question to the community forums following the link included in the search results.
[1.6]001 <?php 002 /* $Id: ldi_check.php,v 2.4 2004/06/15 16:52:18 lem9 Exp $ */ 003 // vim: expandtab sw=4 ts=4 sts=4: 004 005 006 /** 007 * This file checks and builds the sql-string for 008 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name 009 * [FIELDS 010 * [TERMINATED BY '\t'] 011 * [OPTIONALLY] ENCLOSED BY "] 012 * [ESCAPED BY '\\' ]] 013 * [LINES TERMINATED BY '\n'] 014 * [(column_name,...)] 015 */ 016 017 018 /** 019 * Gets some core scripts 020 */ 021 require_once('./libraries/grab_globals.lib.php'); 022 require_once('./libraries/common.lib.php'); 023 024 // Check parameters 025 026 PMA_checkParameters(array('db', 'table')); 027 028 /** 029 * If a file from UploadDir was submitted, use this file 030 */ 031 $unlink_local_textfile = false; 032 if (isset($btnLDI) && isset($local_textfile) && $local_textfile != '') { 033 if (empty($DOCUMENT_ROOT)) { 034 if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) { 035 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; 036 } 037 else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) { 038 $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT']; 039 } 040 else if (@getenv('DOCUMENT_ROOT')) { 041 $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT'); 042 } 043 else { 044 $DOCUMENT_ROOT = '.'; 045 } 046 } // end if 047 048 if (substr($cfg['UploadDir'], -1) != '/') { 049 $cfg['UploadDir'] .= '/'; 050 } 051 $textfile = $DOCUMENT_ROOT . dirname($PHP_SELF) . '/' . preg_replace('@^./@s', '', $cfg['UploadDir']) . PMA_securePath($local_textfile); 052 if (file_exists($textfile)) { 053 $open_basedir = @ini_get('open_basedir'); 054 055 // If we are on a server with open_basedir, we must move the file 056 // before opening it. The doc explains how to create the "./tmp" 057 // directory 058 059 if (!empty($open_basedir)) { 060 061 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/'); 062 063 // function is_writeable() is valid on PHP3 and 4 064 if (!is_writeable($tmp_subdir)) { 065 echo $strWebServerUploadDirectoryError . ': ' . $tmp_subdir 066 . '<br />'; 067 exit(); 068 } else { 069 $textfile_new = $tmp_subdir . basename($textfile); 070 move_uploaded_file($textfile, $textfile_new); 071 $textfile = $textfile_new; 072 $unlink_local_textfile = true; 073 } 074 } 075 } 076 } 077 078 /** 079 * The form used to define the query has been submitted -> do the work 080 */ 081 if (isset($btnLDI) && empty($textfile)) { 082 $js_to_run = 'functions.js'; 083 require_once('./header.inc.php'); 084 $message = $strMustSelectFile; 085 require('./ldi_table.php'); 086 } elseif (isset($btnLDI) && ($textfile != 'none')) { 087 if (!isset($replace)) { 088 $replace = ''; 089 } 090 091 // the error message does not correspond exactly to the error... 092 if (!@chmod($textfile, 0644)) { 093 echo $strFileCouldNotBeRead . ' ' . $textfile . '<br />'; 094 require_once('./footer.inc.php'); 095 } 096 097 // Kanji encoding convert appended by Y.Kawada 098 if (function_exists('PMA_kanji_file_conv')) { 099 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : ''); 100 } 101 102 // Convert the file's charset if necessary 103 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding 104 && isset($charset_of_file) && $charset_of_file != $charset) { 105 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile); 106 } 107 108 // Formats the data posted to this script 109 $textfile = PMA_sqlAddslashes($textfile); 110 $enclosed = PMA_sqlAddslashes($enclosed); 111 $escaped = PMA_sqlAddslashes($escaped); 112 $column_name = PMA_sqlAddslashes($column_name); 113 114 // (try to) make sure the file is readable: 115 chmod($textfile, 0777); 116 117 // Builds the query 118 $sql_query = 'LOAD DATA'; 119 120 if ($local_option == "1") { 121 $sql_query .= ' LOCAL'; 122 } 123 124 $sql_query .= ' INFILE \'' . $textfile . '\''; 125 if (!empty($replace)) { 126 $sql_query .= ' ' . $replace; 127 } 128 $sql_query .= ' INTO TABLE ' . PMA_backquote($into_table); 129 if (isset($field_terminater)) { 130 $sql_query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\''; 131 } 132 if (isset($enclose_option) && strlen($enclose_option) > 0) { 133 $sql_query .= ' OPTIONALLY'; 134 } 135 if (strlen($enclosed) > 0) { 136 $sql_query .= ' ENCLOSED BY \'' . $enclosed . '\''; 137 } 138 if (strlen($escaped) > 0) { 139 $sql_query .= ' ESCAPED BY \'' . $escaped . '\''; 140 } 141 if (strlen($line_terminator) > 0){ 142 $sql_query .= ' LINES TERMINATED BY \'' . $line_terminator . '\''; 143 } 144 if (strlen($column_name) > 0) { 145 $sql_query .= ' ('; 146 $tmp = split(',( ?)', $column_name); 147 $cnt_tmp = count($tmp); 148 for ($i = 0; $i < $cnt_tmp; $i++) { 149 if ($i > 0) { 150 $sql_query .= ', '; 151 } 152 $sql_query .= PMA_backquote(trim($tmp[$i])); 153 } // end for 154 $sql_query .= ')'; 155 } 156 157 // We could rename the ldi* scripts to tbl_properties_ldi* to improve 158 // consistency with the other sub-pages. 159 // 160 // The $goto in ldi_table.php is set to tbl_properties.php but maybe 161 // if would be better to Browse the latest inserted data. 162 require('./sql.php'); 163 if ($unlink_local_textfile) { 164 unlink($textfile); 165 } 166 } 167 168 169 /** 170 * The form used to define the query hasn't been yet submitted -> loads it 171 */ 172 else { 173 require('./ldi_table.php'); 174 } 175 ?> 176 <?php 177 /* $Id: ldi_check.php,v 2.4 2004/06/15 16:52:18 lem9 Exp $ */ 178 // vim: expandtab sw=4 ts=4 sts=4: 179 180 181 /** 182 * This file checks and builds the sql-string for 183 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name 184 * [FIELDS 185 * [TERMINATED BY '\t'] 186 * [OPTIONALLY] ENCLOSED BY "] 187 * [ESCAPED BY '\\' ]] 188 * [LINES TERMINATED BY '\n'] 189 * [(column_name,...)] 190 */ 191 192 193 /** 194 * Gets some core scripts 195 */ 196 require_once('./libraries/grab_globals.lib.php'); 197 require_once('./libraries/common.lib.php'); 198 199 // Check parameters 200 201 PMA_checkParameters(array('db', 'table')); 202 203 /** 204 * If a file from UploadDir was submitted, use this file 205 */ 206 $unlink_local_textfile = false; 207 if (isset($btnLDI) && isset($local_textfile) && $local_textfile != '') { 208 if (empty($DOCUMENT_ROOT)) { 209 if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) { 210 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; 211 } 212 else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) { 213 $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT']; 214 } 215 else if (@getenv('DOCUMENT_ROOT')) { 216 $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT'); 217 } 218 else { 219 $DOCUMENT_ROOT = '.'; 220 } 221 } // end if 222 223 if (substr($cfg['UploadDir'], -1) != '/') { 224 $cfg['UploadDir'] .= '/'; 225 } 226 $textfile = $DOCUMENT_ROOT . dirname($PHP_SELF) . '/' . preg_replace('@^./@s', '', $cfg['UploadDir']) . PMA_securePath($local_textfile); 227 if (file_exists($textfile)) { 228 $open_basedir = @ini_get('open_basedir'); 229 230 // If we are on a server with open_basedir, we must move the file 231 // before opening it. The doc explains how to create the "./tmp" 232 // directory 233 234 if (!empty($open_basedir)) { 235 236 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/'); 237 238 // function is_writeable() is valid on PHP3 and 4 239 if (!is_writeable($tmp_subdir)) { 240 echo $strWebServerUploadDirectoryError . ': ' . $tmp_subdir 241 . '<br />'; 242 exit(); 243 } else { 244 $textfile_new = $tmp_subdir . basename($textfile); 245 move_uploaded_file($textfile, $textfile_new); 246 $textfile = $textfile_new; 247 $unlink_local_textfile = true; 248 } 249 } 250 } 251 } 252 253 /** 254 * The form used to define the query has been submitted -> do the work 255 */ 256 if (isset($btnLDI) && empty($textfile)) { 257 $js_to_run = 'functions.js'; 258 require_once('./header.inc.php'); 259 $message = $strMustSelectFile; 260 require('./ldi_table.php'); 261 } elseif (isset($btnLDI) && ($textfile != 'none')) { 262 if (!isset($replace)) { 263 $replace = ''; 264 } 265 266 // the error message does not correspond exactly to the error... 267 if (!@chmod($textfile, 0644)) { 268 echo $strFileCouldNotBeRead . ' ' . $textfile . '<br />'; 269 require_once('./footer.inc.php'); 270 } 271 272 // Kanji encoding convert appended by Y.Kawada 273 if (function_exists('PMA_kanji_file_conv')) { 274 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : ''); 275 } 276 277 // Convert the file's charset if necessary 278 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding 279 && isset($charset_of_file) && $charset_of_file != $charset) { 280 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile); 281 } 282 283 // Formats the data posted to this script 284 $textfile = PMA_sqlAddslashes($textfile); 285 $enclosed = PMA_sqlAddslashes($enclosed); 286 $escaped = PMA_sqlAddslashes($escaped); 287 $column_name = PMA_sqlAddslashes($column_name); 288 289 // (try to) make sure the file is readable: 290 chmod($textfile, 0777); 291 292 // Builds the query 293 $sql_query = 'LOAD DATA'; 294 295 if ($local_option == "1") { 296 $sql_query .= ' LOCAL'; 297 } 298 299 $sql_query .= ' INFILE \'' . $textfile . '\''; 300 if (!empty($replace)) { 301 $sql_query .= ' ' . $replace; 302 } 303 $sql_query .= ' INTO TABLE ' . PMA_backquote($into_table); 304 if (isset($field_terminater)) { 305 $sql_query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\''; 306 } 307 if (isset($enclose_option) && strlen($enclose_option) > 0) { 308 $sql_query .= ' OPTIONALLY'; 309 } 310 if (strlen($enclosed) > 0) { 311 $sql_query .= ' ENCLOSED BY \'' . $enclosed . '\''; 312 } 313 if (strlen($escaped) > 0) { 314 $sql_query .= ' ESCAPED BY \'' . $escaped . '\''; 315 } 316 if (strlen($line_terminator) > 0){ 317 $sql_query .= ' LINES TERMINATED BY \'' . $line_terminator . '\''; 318 } 319 if (strlen($column_name) > 0) { 320 $sql_query .= ' ('; 321 $tmp = split(',( ?)', $column_name); 322 $cnt_tmp = count($tmp); 323 for ($i = 0; $i < $cnt_tmp; $i++) { 324 if ($i > 0) { 325 $sql_query .= ', '; 326 } 327 $sql_query .= PMA_backquote(trim($tmp[$i])); 328 } // end for 329 $sql_query .= ')'; 330 } 331 332 // We could rename the ldi* scripts to tbl_properties_ldi* to improve 333 // consistency with the other sub-pages. 334 // 335 // The $goto in ldi_table.php is set to tbl_properties.php but maybe 336 // if would be better to Browse the latest inserted data. 337 require('./sql.php'); 338 if ($unlink_local_textfile) { 339 unlink($textfile); 340 } 341 } 342 343 344 /** 345 * The form used to define the query hasn't been yet submitted -> loads it 346 */ 347 else { 348 require('./ldi_table.php'); 349 } 350 ?>
Testing
