Documentation TYPO3 par Ameos

ldi_check.php

00001 <?php
00002 /* $Id: ldi_check.php,v 2.3 2003/11/26 22:52:24 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00021 require_once('./libraries/grab_globals.lib.php');
00022 require_once('./libraries/common.lib.php');
00023 
00024 // Check parameters
00025 
00026 PMA_checkParameters(array('db', 'table'));
00027 
00031 $unlink_local_textfile = false;
00032 if (isset($btnLDI) && isset($local_textfile) && $local_textfile != '') {
00033     if (empty($DOCUMENT_ROOT)) {
00034         if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) {
00035             $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
00036         }
00037         else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) {
00038             $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT'];
00039         }
00040         else if (@getenv('DOCUMENT_ROOT')) {
00041             $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT');
00042         }
00043         else {
00044             $DOCUMENT_ROOT = '.';
00045         }
00046     } // end if
00047 
00048     if (substr($cfg['UploadDir'], -1) != '/') {
00049         $cfg['UploadDir'] .= '/';
00050     }
00051     $textfile = $DOCUMENT_ROOT . dirname($PHP_SELF) . '/' . preg_replace('@^./@s', '', $cfg['UploadDir']) . preg_replace('@\.\.*@', '.', $local_textfile);
00052     if (file_exists($textfile)) {
00053         $open_basedir = @ini_get('open_basedir');
00054 
00055         // If we are on a server with open_basedir, we must move the file
00056         // before opening it. The doc explains how to create the "./tmp"
00057         // directory
00058 
00059         if (!empty($open_basedir)) {
00060 
00061             $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/');
00062 
00063             // function is_writeable() is valid on PHP3 and 4
00064             if (!is_writeable($tmp_subdir)) {
00065                 echo $strWebServerUploadDirectoryError . ': ' . $tmp_subdir
00066                  . '<br />';
00067                 exit();
00068             } else {
00069                 $textfile_new = $tmp_subdir . basename($textfile);
00070                 move_uploaded_file($textfile, $textfile_new);
00071                 $textfile = $textfile_new;
00072                 $unlink_local_textfile = true;
00073             }
00074         }
00075     }
00076 }
00077 
00081 if (isset($btnLDI) && empty($textfile)) {
00082     $js_to_run = 'functions.js';
00083     require_once('./header.inc.php');
00084     $message = $strMustSelectFile;
00085     require('./ldi_table.php');
00086 } elseif (isset($btnLDI) && ($textfile != 'none')) {
00087     if (!isset($replace)) {
00088         $replace = '';
00089     }
00090 
00091     // the error message does not correspond exactly to the error...
00092     if (!@chmod($textfile, 0644)) {
00093        echo $strFileCouldNotBeRead . ' ' . $textfile . '<br />';
00094        require_once('./footer.inc.php');
00095     }
00096 
00097     // Kanji encoding convert appended by Y.Kawada
00098     if (function_exists('PMA_kanji_file_conv')) {
00099         $textfile         = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : '');
00100     }
00101 
00102     // Convert the file's charset if necessary
00103     if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
00104         && isset($charset_of_file) && $charset_of_file != $charset) {
00105         $textfile         = PMA_convert_file($charset_of_file, $convcharset, $textfile);
00106     }
00107 
00108     // Formats the data posted to this script
00109     $textfile             = PMA_sqlAddslashes($textfile);
00110     $enclosed             = PMA_sqlAddslashes($enclosed);
00111     $escaped              = PMA_sqlAddslashes($escaped);
00112     $column_name          = PMA_sqlAddslashes($column_name);
00113 
00114     // (try to) make sure the file is readable:
00115     chmod($textfile, 0777);
00116 
00117     // Builds the query
00118     $sql_query     =  'LOAD DATA';
00119 
00120     if ($local_option == "1") {
00121         $sql_query     .= ' LOCAL';
00122     }
00123 
00124     $sql_query     .= ' INFILE \'' . $textfile . '\'';
00125     if (!empty($replace)) {
00126         $sql_query .= ' ' . $replace;
00127     }
00128     $sql_query     .= ' INTO TABLE ' . PMA_backquote($into_table);
00129     if (isset($field_terminater)) {
00130         $sql_query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
00131     }
00132     if (isset($enclose_option) && strlen($enclose_option) > 0) {
00133         $sql_query .= ' OPTIONALLY';
00134     }
00135     if (strlen($enclosed) > 0) {
00136         $sql_query .= ' ENCLOSED BY \'' . $enclosed . '\'';
00137     }
00138     if (strlen($escaped) > 0) {
00139         $sql_query .= ' ESCAPED BY \'' . $escaped . '\'';
00140     }
00141     if (strlen($line_terminator) > 0){
00142         $sql_query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
00143     }
00144     if (strlen($column_name) > 0) {
00145         $sql_query .= ' (';
00146         $tmp   = split(',( ?)', $column_name);
00147         $cnt_tmp = count($tmp);
00148         for ($i = 0; $i < $cnt_tmp; $i++) {
00149             if ($i > 0) {
00150                 $sql_query .= ', ';
00151             }
00152             $sql_query     .= PMA_backquote(trim($tmp[$i]));
00153         } // end for
00154         $sql_query .= ')';
00155     }
00156 
00157     // We could rename the ldi* scripts to tbl_properties_ldi* to improve
00158     // consistency with the other sub-pages.
00159     //
00160     // The $goto in ldi_table.php is set to tbl_properties.php but maybe
00161     // if would be better to Browse the latest inserted data.
00162     require('./sql.php');
00163     if ($unlink_local_textfile) {
00164         unlink($textfile);
00165     }
00166 }
00167 
00168 
00172 else {
00173     require('./ldi_table.php');
00174 }
00175 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6