php - SQL Export - Wordpress plugin DEV -


hi have following code..

function export_file() {       $tmpname = '/tmp/' . sha1( uniqid() ) . $ext;     $filename = 'export.sql';     $cmd = sprintf( "/applications/xampp/xamppfiles/bin/mysqldump -h'%s' -u'%s' -p'%s' %s --single-transaction %s > %s",         db_host, db_user, db_password, db_name, $compression_pipe, $tmpname );      exec( $cmd );     header( 'content-type: application/bzip' );     header( 'content-length: ' . filesize( $tmpname ) );     header( 'content-disposition: attachment; filename="' . $filename . '"' );     readfile( $tmpname );     unlink( $tmpname );      exit(); } 

now, works doesnt download file. saying headers sent.

headers sent (output started @ /applications/xampp/xamppfiles/htdocs/~/wp-admin/includes/template.php:1642)

now understand headers have been sent main plugin file include javascript , css files needed plugin creating.

 function admin_register_head() { $siteurl = get_option('siteurl'); $css = $siteurl . '/wp-content/plugins/' . basename(dirname(__file__)) . '/style.css'; $script = $siteurl . '/wp-content/plugins/' . basename(dirname(__file__)) . '/script.js'; echo "<link rel='stylesheet' type='text/css' href='$css' />";  echo "<script src='$script' type='application/javascript'>"; } 

how go telling load page again these headers sql dump downloads file , not displayed / file created on server. eg. press link or button , call function , have headers added downloads sql dump file? please correct me if im totally off track here. open suggestions on how this.

i noob , have learnt hell of lot far php, mysql , wordpress creating different elements plugin. appreciated. have searched searched, read tutorials can't seem work. in advanced!

i did figure out now.

if ( isset( $_get['sql_export_export'] ) ) {             export_file(); }  function export_file() {           $tmpname = '/tmp/' . sha1( uniqid() ) . $ext;         $filename = 'export.sql';         $cmd = sprintf( "/applications/xampp/xamppfiles/bin/mysqldump -h'%s' -u'%s' -p'%s' %s --single-transaction %s > %s",             db_host, db_user, db_password, db_name, $compression_pipe, $tmpname );          exec( $cmd );         header( 'content-type: application/bzip' );         header( 'content-length: ' . filesize( $tmpname ) );         header( 'content-disposition: attachment; filename="' . $filename . '"' );         readfile( $tmpname );         unlink( $tmpname );          exit();     }       function database_backup() {       ?><a class="button" href="?sql_export_export">export sql</a><?php      }  

i using xampp on local build plugin wp, replace mysqldump path suit server.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -