-
-
Save joshcangit/ad28f82baf1c9c2fab22dd9e8f39f799 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Import SQL files from a directory | |
* | |
* @author joshcangit, https://github.com/joshcangit | |
* @author Roy-Orbison, https://github.com/Roy-Orbison | |
*/ | |
class AdminerImportFromFolder { | |
protected $dir; | |
/** | |
* @param string $dir optional directory to read from, other than Adminer's current working dir. | |
*/ | |
function __construct($dir = '') { | |
$dir = (string) $dir; | |
if ($dir != '') { | |
$dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; | |
} | |
$this->dir = $dir; | |
} | |
protected function _readFiles($gz = false) { | |
$mapped = array(); | |
$glob = "$this->dir*.[Ss][Qq][Ll]"; | |
if ($gz) { | |
$suffix = '.gz'; # lowercase only because of core | |
$glob .= $suffix; | |
$suffix_cut = -3; | |
} | |
if ($files = glob($glob)) { | |
$from = strlen($this->dir); | |
foreach ($files as $file) { | |
if ($from) { | |
$file = substr($file, $from); # do not expose server paths in output | |
} | |
if ($gz) { | |
$mapped[substr($file, 0, $suffix_cut)] = $file; | |
} | |
else { | |
$mapped[$file] = $file; | |
} | |
} | |
} | |
return $mapped; | |
} | |
function importServerPath() { | |
static $posted = null; | |
$files = $this->_readFiles(); | |
if (extension_loaded('zlib')) { | |
$files += $this->_readFiles(true); # core prioritises files without .gz | |
} | |
if (count($files) > 1) { | |
ksort($files); | |
} | |
if ($posted !== null || !isset($_POST['webfile'])) { | |
# use existing translation strings | |
echo "<fieldset><legend>" . lang('From server') . "</legend><div>"; | |
echo lang('Webserver file %s', '<select name="webfilename">' . optionlist(array('' => lang('Select')) + $files, $posted, true) . '</select>'); | |
echo ' <input type="submit" name="webfile" value="' . lang('Run file') . '">'; | |
echo "</div></fieldset>\n"; | |
$posted = null; | |
return false; # skip core UI | |
} | |
if ( | |
empty($_POST['webfilename']) | |
|| !is_string($_POST['webfilename']) | |
|| !array_key_exists($_POST['webfilename'], $files) | |
) { | |
$posted = ''; | |
return 'SELECTED_FILE_DOES_NOT_EXIST'; # can't return empty string because of core file_exists() check | |
} | |
$posted = $_POST['webfilename']; | |
return $this->dir . $posted; | |
} | |
} |
👍
Drop that close tag though. You don't want the possibility of breaking someone's Adminer install over a style preference.
Drop that close tag though. You don't want the possibility of breaking someone's Adminer install over a style preference.
Now I realize the closing tag wasn't necessary.
how to increase adminer import file limit
how to increase adminer import file limit
🤔
You will need to edit the upload_max_filesize
in the php.ini configuration file if you use the Browse...
button to actually upload a sql file larger than 2MB.
Thanks to @Roy-Orbison, this plugin replaces the adminer.sql[.gz]
with a drop-down menu to select a sql file found in a folder.
I really didn't like how without this plugin, all the databases would need to be in a single file to be imported.
Thought about that for a while. I decided to just copy everthing but keep the filename and class name the same.