Example #1
0
/**
 * Output handler for all exports, if needed buffering, it stores data into
 * $dump_buffer, otherwise it prints thems out.
 *
 * @param   string  the insert statement
 *
 * @return  bool    Whether output suceeded
 */
function PMA_exportOutputHandler($line)
{
    global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
    // Kanji encoding convert feature
    if ($GLOBALS['output_kanji_conversion']) {
        $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
    }
    // If we have to buffer data, we will perform everything at once at the end
    if ($GLOBALS['buffer_needed']) {
        $dump_buffer .= $line;
        if ($GLOBALS['onfly_compression']) {
            $dump_buffer_len += strlen($line);
            if ($dump_buffer_len > $GLOBALS['memory_limit']) {
                if ($GLOBALS['output_charset_conversion']) {
                    $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
                }
                // as bzipped
                if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) {
                    $dump_buffer = bzcompress($dump_buffer);
                } elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
                    // without the optional parameter level because it bug
                    $dump_buffer = gzencode($dump_buffer);
                }
                if ($GLOBALS['save_on_server']) {
                    $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
                    if (!$write_result || $write_result != strlen($dump_buffer)) {
                        $GLOBALS['message'] = PMA_Message::error('strNoSpace');
                        $GLOBALS['message']->addParam($save_filename);
                        return false;
                    }
                } else {
                    echo $dump_buffer;
                }
                $dump_buffer = '';
                $dump_buffer_len = 0;
            }
        } else {
            $time_now = time();
            if ($time_start >= $time_now + 30) {
                $time_start = $time_now;
                header('X-pmaPing: Pong');
            }
            // end if
        }
    } else {
        if ($GLOBALS['asfile']) {
            if ($GLOBALS['output_charset_conversion']) {
                $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line);
            }
            if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
                $write_result = @fwrite($GLOBALS['file_handle'], $line);
                if (!$write_result || $write_result != strlen($line)) {
                    $GLOBALS['message'] = PMA_Message::error('strNoSpace');
                    $GLOBALS['message']->addParam($save_filename);
                    return false;
                }
                $time_now = time();
                if ($time_start >= $time_now + 30) {
                    $time_start = $time_now;
                    header('X-pmaPing: Pong');
                }
                // end if
            } else {
                // We export as file - output normally
                echo $line;
            }
        } else {
            // We export as html - replace special chars
            echo htmlspecialchars($line);
        }
    }
    return true;
}
Example #2
0
                $sql_query = PMA_readFile($sql_file_new, $sql_file_compression);
                if ($sql_query == FALSE) {
                    $message = $strFileCouldNotBeRead;
                }
                unlink($sql_file_new);
            }
        } else {
            // read from the normal upload dir
            $sql_query = PMA_readFile($sql_file, $sql_file_compression);
            if ($sql_query == FALSE) {
                $message = $strFileCouldNotBeRead;
            }
        }
        // Convert the file's charset if necessary
        if ($cfg['AllowAnywhereRecoding'] && $allow_recoding && isset($charset_of_file) && $charset_of_file != $charset) {
            $sql_query = PMA_convert_string($charset_of_file, $charset, $sql_query);
        }
    }
    // end uploaded file stuff
}
// Kanji convert SQL textfile 2002/1/4 by Y.Kawada
if (@function_exists('PMA_kanji_str_conv')) {
    $sql_tmp = trim($sql_query);
    PMA_change_enc_order();
    $sql_query = PMA_kanji_str_conv($sql_tmp, $knjenc, isset($xkana) ? $xkana : '');
    PMA_change_enc_order();
} else {
    $sql_query = trim($sql_query);
}
// $sql_query come from the query textarea, if it's a reposted query gets its
// 'true' value
    /**
     * http://bugs.php.net/bug.php?id=29532
     * bzip reads a maximum of 8192 bytes on windows systems
     * @todo this function is unused
     */
    function getNextChunk($max_size = null)
    {
        if (null !== $max_size) {
            $size = min($max_size, $this->getChunkSize());
        } else {
            $size = $this->getChunkSize();
        }

        // $result = $this->handler->getNextChunk($size);
        $result = '';
        switch ($this->getCompression()) {
            case 'application/bzip2':
                $result = '';
                while (strlen($result) < $size - 8192 && ! feof($this->getHandle())) {
                    $result .= bzread($this->getHandle(), $size);
                }
                break;
            case 'application/gzip':
                $result = gzread($this->getHandle(), $size);
                break;
            case 'application/zip':
                /*
                 * if getNextChunk() is used some day,
                 * replace this code by code similar to the one
                 * in open()
                 *
                include_once './libraries/unzip.lib.php';
                $import_handle = new SimpleUnzip();
                $import_handle->ReadFile($this->getName());
                if ($import_handle->Count() == 0) {
                    $this->_error_message = $GLOBALS['strNoFilesFoundInZip'];
                    return false;
                } elseif ($import_handle->GetError(0) != 0) {
                    $this->_error_message = $GLOBALS['strErrorInZipFile']
                        . ' ' . $import_handle->GetErrorMsg(0);
                    return false;
                } else {
                    $result = $import_handle->GetData(0);
                }
                 */
                break;
            case 'none':
                $result = fread($this->getHandle(), $size);
                break;
            default:
                return false;
        }

        echo $size . ' - ';
        echo strlen($result) . ' - ';
        echo (@$GLOBALS['__len__'] += strlen($result)) . ' - ';
        echo $this->_error_message;
        echo '<hr />';

        if ($GLOBALS['charset_conversion']) {
            $result = PMA_convert_string($this->getCharset(), $GLOBALS['charset'], $result);
        } else {
            /**
             * Skip possible byte order marks (I do not think we need more
             * charsets, but feel free to add more, you can use wikipedia for
             * reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
             *
             * @todo BOM could be used for charset autodetection
             */
            if ($this->getOffset() === 0) {
                // UTF-8
                if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) {
                    $result = substr($result, 3);
                // UTF-16 BE, LE
                } elseif (strncmp($result, "\xFE\xFF", 2) == 0
                 || strncmp($result, "\xFF\xFE", 2) == 0) {
                    $result = substr($result, 2);
                }
            }
        }

        $this->_offset += $size;
        if (0 === $result) {
            return true;
        }
        return $result;
    }
Example #4
0
function PMA_importGetNextChunk($size = 32768)
{
    global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit;
    $compression = 'none';
    // Add some progression while reading large amount of data
    // We can not read too much
    if ($finished) {
        return TRUE;
    }
    switch ($compression) {
        case 'none':
            $result = fread($import_handle, $size);
            $finished = feof($import_handle);
            break;
    }
    $offset += $size;
    if ($charset_conversion) {
        return PMA_convert_string($charset_of_file, $charset, $result);
    } else {
        // Skip possible byte order marks (I do not think we need more
        // charsets, but feel free to add more, you can use wikipedia for
        // reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
        // @TODO: BOM could be used for charset autodetection
        if ($offset == $size) {
            // UTF-8
            if (strncmp($result, "", 3) == 0) {
                $result = substr($result, 3);
                // UTF-16 BE, LE
            } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
                $result = substr($result, 2);
            }
        }
        return $result;
    }
}
Example #5
0
/**
 *  Returns next part of imported file/buffer
 *
 *  @param  integer size of buffer to read (this is maximal size
 *                  function will return)
 *  @return string part of file/buffer
 *  @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $read_limit) {
        $size = $read_limit;
    }
    if (PMA_checkTimeout()) {
        return FALSE;
    }
    if ($finished) {
        return TRUE;
    }
    if ($import_file == 'none') {
        // Well this is not yet supported and tested, but should return content of textarea
        if (strlen($import_text) < $size) {
            $finished = TRUE;
            return $import_text;
        } else {
            $r = substr($import_text, 0, $size);
            $offset += $size;
            $import_text = substr($import_text, $size);
            return $r;
        }
    }
    switch ($compression) {
        case 'application/bzip2':
            $result = bzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/gzip':
            $result = gzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/zip':
            $result = substr($import_text, 0, $size);
            $import_text = substr($import_text, $size);
            $finished = empty($import_text);
            break;
        case 'none':
            $result = fread($import_handle, $size);
            $finished = feof($import_handle);
            break;
    }
    $offset += $size;
    if ($charset_conversion) {
        return PMA_convert_string($charset_of_file, $charset, $result);
    } else {
        return $result;
    }
}
                     echo $strFileCouldNotBeRead;
                     exit;
                 }
             } else {
                 $sql_file_new = $tmp_subdir . basename($sql_file);
                 move_uploaded_file($sql_file, $sql_file_new);
                 $docsql_text = PMA_readFile($sql_file_new, $sql_file_compression);
                 unlink($sql_file_new);
             }
         } else {
             // read from the normal upload dir
             $docsql_text = PMA_readFile($sql_file, $sql_file_compression);
         }
         // Convert the file's charset if necessary
         if ($cfg['AllowAnywhereRecoding'] && $allow_recoding && isset($charset_of_file) && $charset_of_file != $charset) {
             $docsql_text = PMA_convert_string($charset_of_file, $charset, $docsql_text);
         }
         if (!isset($docsql_text) || $docsql_text == FALSE || $docsql_text == '') {
             echo '<p><font color="red">' . $GLOBALS['strFileCouldNotBeRead'] . '</font></p>' . "\n";
         } else {
             docsql_check('', $sql_file_name, $sql_file_name, $docsql_text);
         }
     }
     // end uploaded file stuff
 } else {
     // echo '<h1>Starting Import</h1>';
     $docpath = $cfg['docSQLDir'] . PMA_securePath($docpath);
     if (substr($docpath, -1) != '/') {
         $docpath .= '/';
     }
     $matched_files = 0;
/**
 * Returns next part of imported file/buffer
 *
 * @uses    $GLOBALS['offset'] read and write
 * @uses    $GLOBALS['import_file'] read only
 * @uses    $GLOBALS['import_text'] read and write
 * @uses    $GLOBALS['finished'] read and write
 * @uses    $GLOBALS['read_limit'] read only
 * @param  integer size of buffer to read (this is maximal size
 *                  function will return)
 * @return string part of file/buffer
 * @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $compression, $import_handle, $charset_conversion, $charset_of_file, $charset, $read_multiply;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $GLOBALS['read_limit']) {
        $size = $GLOBALS['read_limit'];
    }
    if (PMA_checkTimeout()) {
        return FALSE;
    }
    if ($GLOBALS['finished']) {
        return TRUE;
    }
    if ($GLOBALS['import_file'] == 'none') {
        // Well this is not yet supported and tested, but should return content of textarea
        if (strlen($GLOBALS['import_text']) < $size) {
            $GLOBALS['finished'] = TRUE;
            return $GLOBALS['import_text'];
        } else {
            $r = substr($GLOBALS['import_text'], 0, $size);
            $GLOBALS['offset'] += $size;
            $GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size);
            return $r;
        }
    }
    switch ($compression) {
        case 'application/bzip2':
            $result = bzread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
        case 'application/gzip':
            $result = gzread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
        case 'application/zip':
            $result = substr($GLOBALS['import_text'], 0, $size);
            $GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size);
            $GLOBALS['finished'] = empty($GLOBALS['import_text']);
            break;
        case 'none':
            $result = fread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
    }
    $GLOBALS['offset'] += $size;
    if ($charset_conversion) {
        return PMA_convert_string($charset_of_file, $charset, $result);
    } else {
        /**
         * Skip possible byte order marks (I do not think we need more
         * charsets, but feel free to add more, you can use wikipedia for
         * reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
         *
         * @todo BOM could be used for charset autodetection
         */
        if ($GLOBALS['offset'] == $size) {
            // UTF-8
            if (strncmp($result, "", 3) == 0) {
                $result = substr($result, 3);
                // UTF-16 BE, LE
            } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
                $result = substr($result, 2);
            }
        }
        return $result;
    }
}