发送标题然后刷新页面?

时间:2014-02-20 22:00:41

标签: php mysqli

我今天早些时候曾问过我的数据库备份系统

以下是链接:database backup system

这是代码

if (isset($_POST['getbackup'])) { 
        /* setcookie("backupdisable", 1, time()*60*60*24); */ 
        $db = "newsite";
        $version = "2.3.1";
        $date = date('Y-m-d H:i:s');

        $final = "--   #".$version."#\n";
        $final .= "--   database backup\n";
        $final .= "--\n";
        $final .= "--   PHP version: ".phpversion()."\n";
        $final .= "--   MySQL version: ".mysqli_get_server_info($mysqli)."\n";
        $final .= "--   Date: ".date("r")."\n";

        $result = $mysqli->query("SHOW TABLE STATUS FROM ".$db);
        while ($table = $result->fetch_array()) {
        $i = 0;
        $result2 = $mysqli->query("SHOW COLUMNS FROM $table[0]");
        $z = $result2->num_rows;
        $final .= "\n--\n-- DB Export - Table structure for table `".$table[0]."`\n--\n\nCREATE TABLE `".$table[0]."` (";
        $prikey = false;
        $insert_keys = null;
        while ($row2 = $result2->fetch_array()) {
            $i++;
            $insert_keys .="`".$row2['Field']."`";
            $final .= "`".$row2['Field']."` ".$row2['Type'];
            if($row2['Null'] != "YES") { $final .= " NOT NULL"; }
            if($row2['Default']) $final .= " DEFAULT '".$row2['Default']."'";
            if($row2['Extra']) { $final .= " ".$row2['Extra']; }
            if($row2['Key'] == "PRI") { $final .= ", PRIMARY KEY  (`".$row2['Field']."`)"; $prikey = true; }
            if($i < $z){
                $final .= ", ";
                $insert_keys .=", ";
            }
            else{
                $final .= " ";
            }
        }
        if($prikey) {
            if($table[10]) $auto_inc = " AUTO_INCREMENT=".$table[10];
            else $auto_inc = " AUTO_INCREMENT=1";
        }
        else $auto_inc = "";
        $charset = explode("_", $table[14]);
        $final .= ") ENGINE=".$table[1]." DEFAULT CHARSET=".$charset[0]." COLLATE=".$table[14].$auto_inc.";\n\n--\n-- DB Export - Dumping data for table `".$table[0]."`\n--\n";

        $inhaltq = $mysqli->query("SELECT * FROM $table[0]");
        while($inhalt = $inhaltq->fetch_array()) {
            $final .= "\nINSERT INTO `$table[0]` (";
            $final .= $insert_keys;
            $final .= ") VALUES (";
            for($i=0;$i<$z;$i++) {

                $inhalt[$i] = str_replace("'","`", $inhalt[$i]);
                $inhalt[$i] = str_replace("\\","\\\\", $inhalt[$i]);
                $einschub = "'".$inhalt[$i]."'";
                $final .= preg_replace('/\r\n|\r|\n/', '\r\n', $einschub);
                if(($i+1)<$z) $final .= ", ";

            }
            $final .= ");";
        }
        $final .= "\n";
    }
    if($logged) {

        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Description: File Transfer");
        if(is_integer(mb_strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "msie")) AND is_integer(mb_strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "win" ))) header("Content-Disposition: filename=backup-".strtolower(date("D-d-M-Y")).".sql;");
        else header("Content-Disposition: attachment; filename=backup-".strtolower(date("D-d-M-Y")).".sql;");
        header("Content-Transfer-Encoding: binary");
        echo $final;
        exit;
    }
    }

我现在的问题是:

脚本工作正常,但是现在我尝试在获取此文件后删除提交按钮,这可能吗?

如果我刷新页面按钮将被删除,但我不知道该怎么做..

因为如果我设置了刷新的标题我无法下载文件

0 个答案:

没有答案