]> git.joonet.de Git - adminer.git/commitdiff
Allow more SQL files to be uploaded at the same time (thanks to Frantisek Svoboda)
authorJakub Vrana <jakub@vrana.cz>
Fri, 26 Apr 2013 20:26:08 +0000 (13:26 -0700)
committerJakub Vrana <jakub@vrana.cz>
Fri, 26 Apr 2013 20:26:08 +0000 (13:26 -0700)
adminer/include/functions.inc.php
adminer/sql.inc.php
changes.txt

index 34415b33134ed8a48eb99d20826c56f79054847d..be3ca27d660a9bed9986dbccf57e2411a7fc0c05 100644 (file)
@@ -569,22 +569,35 @@ function pagination($page, $current) {
 */
 function get_file($key, $decompress = false) {
        $file = $_FILES[$key];
-       if (!$file || $file["error"]) {
-               return $file["error"];
-       }
-       $return = file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]"
-               : ($decompress && ereg('\\.bz2$', $file["name"]) ? "compress.bzip2://$file[tmp_name]"
-               : $file["tmp_name"]
-       )); //! may not be reachable because of open_basedir
-       if ($decompress) {
-               $start = substr($return, 0, 3);
-               if (function_exists("iconv") && ereg("^\xFE\xFF|^\xFF\xFE", $start, $regs)) { // not ternary operator to save memory
-                       $return = iconv("utf-16", "utf-8", $return);
-               } elseif ($start == "\xEF\xBB\xBF") { // UTF-8 BOM
-                       $return = substr($return, 3);
+       if (!$file) {
+               return null;
+       }
+       foreach ($file as $key => $val) {
+               $file[$key] = (array) $val;
+       }
+       $return = array();
+       foreach ($file["error"] as $key => $error) {
+               if ($error) {
+                       return $error;
                }
+               $name = $file["name"][$key];
+               $tmp_name = $file["tmp_name"][$key];
+               $content = file_get_contents($decompress && ereg('\\.gz$', $name) ? "compress.zlib://$tmp_name"
+                       : ($decompress && ereg('\\.bz2$', $name) ? "compress.bzip2://$tmp_name"
+                       : $tmp_name
+               )); //! may not be reachable because of open_basedir
+               if ($decompress) {
+                       $start = substr($content, 0, 3);
+                       if (function_exists("iconv") && ereg("^\xFE\xFF|^\xFF\xFE", $start, $regs)) { // not ternary operator to save memory
+                               $content = iconv("utf-16", "utf-8", $content);
+                       } elseif ($start == "\xEF\xBB\xBF") { // UTF-8 BOM
+                               $content = substr($content, 3);
+                       }
+               }
+               $return[] = $content;
        }
-       return $return;
+       //! support SQL files not ending with semicolon
+       return implode("\n\n\n", $return);
 }
 
 /** Determine upload error
index b8c332cc4c739a43a95c308961af0c3442b4e5aa..67d26d64ac83544512106801f9c3842f085c47b0 100644 (file)
@@ -25,7 +25,7 @@ if (!$error && $_POST) {
                        : "compress.bzip2://adminer.sql.bz2"
                )), "rb");
                $query = ($fp ? fread($fp, 1e6) : false);
-       } elseif ($_FILES && $_FILES["sql_file"]["error"] != UPLOAD_ERR_NO_FILE) {
+       } elseif ($_FILES && $_FILES["sql_file"]["error"][0] != 4) { // 4 - UPLOAD_ERR_NO_FILE
                $query = get_file("sql_file", true);
        }
        if (is_string($query)) { // get_file() returns error as number, fread() as false
@@ -180,7 +180,9 @@ if ($_POST) {
 textarea("query", $q, 20);
 echo ($_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n");
 echo "<p>" . (ini_bool("file_uploads")
-       ? lang('File upload') . ': <input type="file" name="sql_file"' . ($_FILES && $_FILES["sql_file"]["error"] != 4 ? '' : ' onchange="this.form[\'only_errors\'].checked = true;"') . '> (&lt; ' . ini_get("upload_max_filesize") . 'B)' // ignore post_max_size because it is for all form fields together and bytes computing would be necessary
+       ? lang('File upload') . ': <input type="file" name="sql_file[]" multiple'
+               . ($_FILES && $_FILES["sql_file"]["error"][0] != 4 ? '' : ' onchange="this.form[\'only_errors\'].checked = true;"') // 4 - UPLOAD_ERR_NO_FILE
+               . '> (&lt; ' . ini_get("upload_max_filesize") . 'B)' // ignore post_max_size because it is for all form fields together and bytes computing would be necessary
        : lang('File uploads are disabled.')
 );
 
index b71301371de0318b7e255e1f8c7c1753ee9bc363..c3264ad76260262b65851b54e2a1eb6e2343a857 100644 (file)
@@ -1,4 +1,5 @@
-Adminer 3.6.5-dev:
+Adminer 3.7.0-dev:
+Allow more SQL files to be uploaded at the same time
 Print run time next to executed queries
 Disable SQL export when applying functions in select
 Fix handling of POINT data type (bug #3582578)