0

I use this codes to download MySQL Database on Server Side it works fine but I don't know how to download Database on Client Side, please help.

        include'connect.php';
    if(isset($_POST['download'])){

        $time = time();
        $current_date_time = date('d-m-Y@H-i-s', strtotime('+3 hours'));
        $backupFile = 'D://xampp//htdocs//development//ShahrajeTraders//backup//'.$database.'~'.$current_date_time.'.sql';
        $command = "D://xampp//mysql//bin//mysqldump.exe -h $host_name -u $user_name -p$user_pass $database > $backupFile";
        system($command);

        if($command){
            echo'
            <script>
                $(document).ready(function(){
                    alert("Download Completed.");   
                }); 
            </script>
            ';          
        }else{
            echo'               
            <script>
                $(document).ready(function(){
                    alert("Error During Downloading."); 
                }); 
            </script>
            ';
        }
    } 
khkhizar
  • 147
  • 1
  • 1
  • 5

1 Answers1

0

You will need to point the browser to the URL of the backup file.

I assume that you already sends content to the browser (say, you do echo calls before this code), so a possibility would be to set a location to the client (browser) with JavaScript.

In your case it could look like this

if($command){
        echo'
        <script>
            $(document).ready(function(){
                window.location="/development/ShahrajeTraders/backup/'.$database.'~'.$current_date_time.'.sql";
            }); 
        </script>
        ';          
    }else{
        echo'               
        <script>
            $(document).ready(function(){
                alert("Error During Downloading."); 
            }); 
        </script>
        ';
    }

I don't know the configuration of your web server, so you will need to adjust the URL in the code.

Jens L.
  • 118
  • 6