]> git.joonet.de Git - adminer.git/commitdiff
Respect original memory_limit
authorJakub Vrana <jakub@vrana.cz>
Wed, 24 Aug 2011 12:16:11 +0000 (14:16 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 24 Aug 2011 12:16:11 +0000 (14:16 +0200)
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/sql.inc.php

index df1ebe2e11678ed8f72b5f34ee148fb4e956dbdb..bc40d4ccd26955d7d0c358bfe28f63c12e8c2897 100644 (file)
@@ -366,3 +366,17 @@ function tar_file($filename, $contents) {
        $return .= sprintf("%06o", $checksum) . "\0 ";
        return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
 }
+
+/** Get INI bytes value
+* @param string
+* @return int
+*/
+function ini_bytes($ini) {
+       $val = ini_get($ini);
+       switch (strtolower(substr($val, -1))) {
+               case 'g': $val *= 1024; // no break
+               case 'm': $val *= 1024; // no break
+               case 'k': $val *= 1024;
+       }
+       return $val;
+}
index 04b79888b010021e9498c36ef5144444e372fa60..9a5c40bb93adb2f9cc8809b142105f4ff6bd96a5 100644 (file)
@@ -571,7 +571,7 @@ function get_file($key, $decompress = false) {
 * @return string
 */
 function upload_error($error) {
-       $max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : null); // post_max_size is checked in index.php
+       $max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : 0); // post_max_size is checked in index.php
        return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.'));
 }
 
index 762f0273c72fbc31f9f129aa9df1e6a5dfe165dc..e4d135f523dccca4712f08be531cfa9e85242796 100644 (file)
@@ -25,12 +25,12 @@ if (!$error && $_POST) {
                        : "compress.bzip2://adminer.sql.bz2"
                )), "rb");
                $query = ($fp ? fread($fp, 1e6) : false);
-       } elseif ($_FILES && $_FILES["sql_file"]["error"] != 4) { // 4 - UPLOAD_ERR_NO_FILE
+       } elseif ($_FILES && $_FILES["sql_file"]["error"] != UPLOAD_ERR_NO_FILE) {
                $query = get_file("sql_file", true);
        }
        if (is_string($query)) { // get_file() returns error as number, fread() as false
                if (function_exists('memory_get_usage')) {
-                       @ini_set("memory_limit", max(ini_get("memory_limit"), 2 * strlen($query) + memory_get_usage() + 8e6)); // @ - may be disabled, 2 - substr and trim, 8e6 - other variables
+                       @ini_set("memory_limit", max(ini_bytes("memory_limit"), 2 * strlen($query) + memory_get_usage() + 8e6)); // @ - may be disabled, 2 - substr and trim, 8e6 - other variables
                }
                if ($query != "" && strlen($query) < 1e6) { // don't add big queries
                        $q = $query . (ereg(';$', $query) ? "" : ";"); //! doesn't work with DELIMITER |