简体   繁体   中英

php fails to restore backup sql

i'm creating a restore database script in php but its not working. this is the code so far

<form action = '' method = 'POST'>
            <h2>Restore</h2>
            <table>
            <tr><td><input type=file name="file"></td></tr>
            <tr><td><input type = 'submit' name = "restore" value="restore"></tr></td>
            </table>
        </form>

        <?php
        $host = 'localhost';
        $user = 'root';
        $pass = ' ';
        $dbname = 'itravel';
        //date_default_timezone_set('Asia/Kuala_Lumpur'); 
        //$currentdate = date('YmdGis');
        $restore_name = $_POST['file'];
        $custompath = $_POST['path'];

        if(isset($_POST['restore']))
        {
                $restore = "c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name";
                system($restore);

        }
        ?>

nothing happening after clicking the restore button. please help

$restore = "c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name";
                                                                  ^^^^^^^^^^^

nowhere do you define $backup_name . Shouldn't it be $restore_name ?

Uploads also do not appear in $_POST . They show up via $_FILES .

You should also NEVER assuming an upload succeeded. Especially for a mysql dump file. It is possible that the upload was truncated, yet you blindly feed the file back into MySQL, which could leave you with a partially/totally trashed database.

ALWAYS check for upload errors:

if ($_FILES['files']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error " . $_FILES['files']['error']);
}

$restore_name = $_FILES['files']['tmp_name']; // temp file PHP stores upload in

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM