22
22
'chset ' =>"utf8 " ,#optional, default charset
23
23
);
24
24
$ 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
26
file_exists ($ f =dirname (__FILE__ ) . '/phpminiconfig.php ' )&&require ($ f ); // Read from config (easier to update)
26
27
if (function_exists ('date_default_timezone_set ' )) date_default_timezone_set ('UTC ' );#required by PHP 5.1+
27
28
28
29
//constants
29
- $ VERSION ='1.9.160705 ' ;
30
+ $ VERSION ='1.9.161116 ' ;
30
31
$ MAX_ROWS_PER_PAGE =50 ; #max number of rows in select per one page
31
32
$ D ="\r\n" ; #default delimiter for export
32
33
$ BOM =chr (239 ).chr (187 ).chr (191 );
@@ -788,7 +789,7 @@ function loadsess(){
788
789
}
789
790
790
791
function print_export (){
791
- global $ self ,$ xurl ,$ DB ;
792
+ global $ self ,$ xurl ,$ DB , $ DUMP_FILE ;
792
793
$ t =$ _REQUEST ['rt ' ];
793
794
$ l =($ t )?"Table $ t " :"whole DB " ;
794
795
print_header ();
@@ -812,16 +813,24 @@ function print_export(){
812
813
<br>
813
814
<input type="hidden" name="doex" value="1">
814
815
<input type="hidden" name="rt" value="<?php eo ($ t )?> ">
815
- <input type="submit" value=" Download "><input type="button" value=" Cancel " onclick="window.location='<?php eo ($ self .'? ' .$ xurl .'&db= ' .$ DB ['db ' ])?> '">
816
+ <input type="submit" value=" Download ">
817
+ <input type="submit" name="srv" value=" Dump on Server ">
818
+ <input type="button" value=" Cancel " onclick="window.location='<?php eo ($ self .'? ' .$ xurl .'&db= ' .$ DB ['db ' ])?> '">
819
+ <p><small>"Dump on Server" exports to file:<br><?php eo (export_fname ($ DUMP_FILE ).'.sql ' )?> </small></p>
816
820
</div>
817
821
</center>
818
822
<?php
819
823
print_footer ();
820
824
exit ;
821
825
}
822
826
827
+ function export_fname ($ f ,$ ist =false ){
828
+ $ t =$ ist ?date ('Y-m-d-His ' ):'YYYY-MM-DD-HHMMSS ' ;
829
+ return $ f .$ t ;
830
+ }
831
+
823
832
function do_export (){
824
- global $ DB ,$ VERSION ,$ D ,$ BOM ,$ ex_isgz ,$ dbh ;
833
+ global $ DB ,$ VERSION ,$ D ,$ BOM ,$ ex_isgz ,$ ex_issrv , $ dbh, $ out_message ;
825
834
$ rt =str_replace ('` ' ,'' ,$ _REQUEST ['rt ' ]);
826
835
$ t =explode (", " ,$ rt );
827
836
$ th =array_flip ($ t );
@@ -836,9 +845,10 @@ function do_export(){
836
845
if ($ ex_isgz ) {
837
846
$ aext ='.gz ' ;$ ctp ='application/x-gzip ' ;
838
847
}
839
- ex_start () ;
848
+ $ ex_issrv =( $ _REQUEST [ ' srv ' ])? 1 : 0 ;
840
849
841
850
if ($ ct ==1 &&$ _REQUEST ['et ' ]=='csv ' ){
851
+ ex_start ('.csv ' );
842
852
ex_hdr ($ ctp ?$ ctp :'text/csv ' ,"$ t [0 ].csv $ aext " );
843
853
if ($ DB ['chset ' ]=='utf8 ' ) ex_w ($ BOM );
844
854
@@ -850,29 +860,29 @@ function do_export(){
850
860
}
851
861
ex_w ($ D );
852
862
while ($ row =mysqli_fetch_row ($ sth )) ex_w (to_csv_row ($ row ));
853
- ex_end ();
854
- exit ;
855
- }
856
-
857
- ex_hdr ($ ctp ?$ ctp :'text/plain ' ,"$ DB [db]" .(($ ct ==1 &&$ t [0 ])?". $ t [0 ]" :(($ ct >1 )?'. ' .$ ct .'tables ' :'' )).".sql $ aext " );
858
- ex_w ("-- phpMiniAdmin dump $ VERSION $ D-- Datetime: " .date ('Y-m-d H:i:s ' )."$ D-- Host: $ DB [host]$ D-- Database: $ DB [db]$ D$ D " );
859
- ex_w ("/*!40030 SET NAMES $ DB [chset] */; $ D " );
860
- $ ex_super && ex_w ("/*!40030 SET GLOBAL max_allowed_packet=16777216 */; $ D$ D " );
861
- ex_w ("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; $ D$ D " );
863
+ }else {
864
+ ex_start ('.sql ' );
865
+ ex_hdr ($ ctp ?$ ctp :'text/plain ' ,"$ DB [db]" .(($ ct ==1 &&$ t [0 ])?". $ t [0 ]" :(($ ct >1 )?'. ' .$ ct .'tables ' :'' )).".sql $ aext " );
866
+ 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 " );
868
+ $ ex_super && ex_w ("/*!40030 SET GLOBAL max_allowed_packet=16777216 */; $ D$ D " );
869
+ ex_w ("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; $ D$ D " );
870
+
871
+ $ sth =db_query ("show tables from ` $ DB [db]` " );
872
+ while ($ row =mysqli_fetch_row ($ sth )){
873
+ if (!$ rt ||array_key_exists ($ row [0 ],$ th )) do_export_table ($ row [0 ],1 ,$ MAXI );
874
+ }
862
875
863
- $ sth =db_query ("show tables from ` $ DB [db]` " );
864
- while ($ row =mysqli_fetch_row ($ sth )){
865
- if (!$ rt ||array_key_exists ($ row [0 ],$ th )) do_export_table ($ row [0 ],1 ,$ MAXI );
876
+ ex_w ("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; $ D$ D " );
877
+ ex_w ("$ D-- phpMiniAdmin dump end $ D " );
866
878
}
867
-
868
- ex_w ("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; $ D$ D " );
869
- ex_w ("$ D-- phpMiniAdmin dump end $ D " );
870
879
ex_end ();
871
- exit ;
880
+ if (!$ ex_issrv ) exit ;
881
+ $ out_message ='Export done successfully ' ;
872
882
}
873
883
874
884
function do_export_table ($ t ='' ,$ isvar =0 ,$ MAXI =838860 ){
875
- global $ D ;
885
+ global $ D, $ ex_issrv ;
876
886
@set_time_limit (600 );
877
887
878
888
if ($ _REQUEST ['s ' ]){
@@ -897,34 +907,46 @@ function do_export_table($t='',$isvar=0,$MAXI=838860){
897
907
if ($ exsql ) ex_w ("INSERT INTO ` $ t` VALUES $ exsql; $ D " );
898
908
ex_w ("/*!40000 ALTER TABLE ` $ t` ENABLE KEYS */; $ D$ D " );
899
909
}
900
- flush ();
910
+ if (! $ ex_issrv ) flush ();
901
911
}
902
912
903
913
function ex_hdr ($ ct ,$ fn ){
914
+ global $ ex_issrv ;
915
+ if ($ ex_issrv ) return ;
904
916
header ("Content-type: $ ct " );
905
917
header ("Content-Disposition: attachment; filename= \"$ fn \"" );
906
918
}
907
- function ex_start (){
908
- global $ ex_isgz ,$ ex_gz ,$ ex_tmpf ;
919
+ function ex_start ($ ext ){
920
+ global $ ex_isgz ,$ ex_gz ,$ ex_tmpf, $ ex_issrv , $ ex_f , $ DUMP_FILE ;
909
921
if ($ ex_isgz ){
910
- $ ex_tmpf =tmp_name ().'.gz ' ;
922
+ $ ex_tmpf =( $ ex_issrv ? export_fname ( $ DUMP_FILE , true ). $ ext : tmp_name () ).'.gz ' ;
911
923
if (!($ ex_gz =gzopen ($ ex_tmpf ,'wb9 ' ))) die ("Error trying to create gz tmp file " );
924
+ }else {
925
+ if ($ ex_issrv ) $ ex_f =fopen (export_fname ($ DUMP_FILE ,true ).$ ext ,'wb ' );
912
926
}
913
927
}
914
928
function ex_w ($ s ){
915
- global $ ex_isgz ,$ ex_gz ;
929
+ global $ ex_isgz ,$ ex_gz, $ ex_issrv , $ ex_f ;
916
930
if ($ ex_isgz ){
917
931
gzwrite ($ ex_gz ,$ s ,strlen ($ s ));
918
932
}else {
919
- echo $ s ;
933
+ if ($ ex_issrv ){
934
+ fwrite ($ ex_f ,$ s );
935
+ }else {
936
+ echo $ s ;
937
+ }
920
938
}
921
939
}
922
940
function ex_end (){
923
- global $ ex_isgz ,$ ex_gz ,$ ex_tmpf ;
941
+ global $ ex_isgz ,$ ex_gz ,$ ex_tmpf, $ ex_issrv , $ ex_f ;
924
942
if ($ ex_isgz ){
925
943
gzclose ($ ex_gz );
926
- readfile ($ ex_tmpf );
927
- unlink ($ ex_tmpf );
944
+ if (!$ ex_issrv ){
945
+ readfile ($ ex_tmpf );
946
+ unlink ($ ex_tmpf );
947
+ }
948
+ }else {
949
+ if ($ ex_issrv ) fclose ($ ex_f );
928
950
}
929
951
}
930
952
0 commit comments