Skip to content

Commit 4ab6851

Browse files
committed
added ability to import from .sql or .gz file right on server, without need to upload one. Fixed export for views
1 parent 51bf3ad commit 4ab6851

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ In the directory samples you'll find phpminiconfig.php for known OpenSource pack
3333
## Change Log
3434
### changes in phpMiniAdmin 1.9.161116
3535
- added ability to dump exports right on server, without need to download
36+
- added ability to import from .sql or .gz file right on server, without need to upload one
37+
- fixed export, now it won't dump data for VIEWs
3638

3739
### changes in phpMiniAdmin 1.9.160705
3840
- screen appearance changes/fixes

phpminiadmin.php

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'chset'=>"utf8",#optional, default charset
2323
);
2424
$IS_COUNT=false; #set to true if you want to see Total records when pagination occurs (SLOWS down all select queries!)
25-
$DUMP_FILE=dirname(__FILE__).'/ppmdump'; #path to file without extension used for server-side exports (timestamp, .sql/.csv/.gz extension added) or imports(.sql)
25+
$DUMP_FILE=dirname(__FILE__).'/pmadump'; #path to file without extension used for server-side exports (timestamp, .sql/.csv/.gz extension added) or imports(.sql)
2626
file_exists($f=dirname(__FILE__) . '/phpminiconfig.php')&&require($f); // Read from config (easier to update)
2727
if (function_exists('date_default_timezone_set')) date_default_timezone_set('UTC');#required by PHP 5.1+
2828

@@ -864,13 +864,13 @@ function do_export(){
864864
ex_start('.sql');
865865
ex_hdr($ctp?$ctp:'text/plain',"$DB[db]".(($ct==1&&$t[0])?".$t[0]":(($ct>1)?'.'.$ct.'tables':'')).".sql$aext");
866866
ex_w("-- phpMiniAdmin dump $VERSION$D-- Datetime: ".date('Y-m-d H:i:s')."$D-- Host: $DB[host]$D-- Database: $DB[db]$D$D");
867-
ex_w("/*!40030 SET NAMES $DB[chset] */;$D");
867+
if ($DB['chset']) ex_w("/*!40030 SET NAMES $DB[chset] */;$D");
868868
$ex_super && ex_w("/*!40030 SET GLOBAL max_allowed_packet=16777216 */;$D$D");
869869
ex_w("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;$D$D");
870870

871-
$sth=db_query("show tables from `$DB[db]`");
871+
$sth=db_query("show full tables from `$DB[db]`");
872872
while($row=mysqli_fetch_row($sth)){
873-
if (!$rt||array_key_exists($row[0],$th)) do_export_table($row[0],1,$MAXI);
873+
if (!$rt||array_key_exists($row[0],$th)) do_export_table($row[0],$row[1],$MAXI);
874874
}
875875

876876
ex_w("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;$D$D");
@@ -881,7 +881,7 @@ function do_export(){
881881
$out_message='Export done successfully';
882882
}
883883

884-
function do_export_table($t='',$isvar=0,$MAXI=838860){
884+
function do_export_table($t='',$tt='',$MAXI=838860){
885885
global $D,$ex_issrv;
886886
@set_time_limit(600);
887887

@@ -892,7 +892,7 @@ function do_export_table($t='',$isvar=0,$MAXI=838860){
892892
ex_w("DROP TABLE IF EXISTS `$t`;$D$ct;$D$D");
893893
}
894894

895-
if ($_REQUEST['d']){
895+
if ($_REQUEST['d']&&$tt!='VIEW'){//no dump for views
896896
$exsql='';
897897
ex_w("/*!40000 ALTER TABLE `$t` DISABLE KEYS */;$D");
898898
$sth=db_query("select * from `$t`");
@@ -951,15 +951,21 @@ function ex_end(){
951951
}
952952

953953
function print_import(){
954-
global $self,$xurl,$DB;
954+
global $self,$xurl,$DB,$DUMP_FILE;
955955
print_header();
956956
?>
957957
<center>
958958
<h3>Import DB</h3>
959959
<div class="frm">
960-
<b>.sql</b> or <b>.gz</b> file: <input type="file" name="file1" value="" size=40><br>
960+
<div><label><input type="radio" name="it" value="" checked> import by uploading <b>.sql</b> or <b>.gz</b> file:</label>
961+
<input type="file" name="file1" value="" size=40><br>
962+
</div>
963+
<div><label><input type="radio" name="it" value="sql"> import from file on server:<br>
964+
<?php eo($DUMP_FILE.'.sql')?></label></div>
965+
<div><label><input type="radio" name="it" value="gz"> import from file on server:<br>
966+
<?php eo($DUMP_FILE.'.sql.gz')?></label></div>
961967
<input type="hidden" name="doim" value="1">
962-
<input type="submit" value=" Upload and Import " onclick="return ays()"><input type="button" value=" Cancel " onclick="window.location='<?php eo($self.'?'.$xurl.'&db='.$DB['db'])?>'">
968+
<input type="submit" value=" Import " onclick="return ays()"><input type="button" value=" Cancel " onclick="window.location='<?php eo($self.'?'.$xurl.'&db='.$DB['db'])?>'">
963969
</div>
964970
<br><br><br>
965971
<!--
@@ -993,14 +999,24 @@ function print_import(){
993999
}
9941000

9951001
function do_import(){
996-
global $err_msg,$out_message,$dbh,$SHOW_T;
1002+
global $err_msg,$out_message,$dbh,$SHOW_T,$DUMP_FILE;
9971003
$err_msg='';
998-
$F=$_FILES['file1'];
1004+
$it=$_REQUEST['it'];
1005+
1006+
if (!$it){
1007+
$F=$_FILES['file1'];
1008+
if ($F && $F['name']){
1009+
$filename=$F['tmp_name'];
1010+
$pi=pathinfo($F['name']);
1011+
$ext=$pi['extension'];
1012+
}
1013+
}else{
1014+
$ext=($it=='gz'?'sql.gz':'sql');
1015+
$filename=$DUMP_FILE.'.'.$ext;
1016+
}
9991017

1000-
if ($F && $F['name']){
1001-
$filename=$F['tmp_name'];
1002-
$pi=pathinfo($F['name']);
1003-
if ($pi['extension']!='sql'){//if not sql - assume .gz
1018+
if ($filename && file_exists($filename)){
1019+
if ($ext!='sql'){//if not sql - assume .gz and extract
10041020
$tmpf=tmp_name();
10051021
if (($gz=gzopen($filename,'rb')) && ($tf=fopen($tmpf,'wb'))){
10061022
while(!gzeof($gz)){
@@ -1017,8 +1033,9 @@ function do_import(){
10171033
do_sql($SHOW_T);
10181034
return;
10191035
}}
1036+
10201037
}else{
1021-
$err_msg="Error: Please select file first";
1038+
$err_msg="Error: Please select file first";
10221039
}
10231040
print_import();
10241041
exit;

0 commit comments

Comments
 (0)