gpt4 book ai didi

php - 将数据库备份保存在服务器上而不是推送给用户

转载 作者:行者123 更新时间:2023-11-29 12:55:24 24 4
gpt4 key购买 nike

下面是我如何生成 MySql 数据库备份并强制将其下载到用户计算机上:

    $DBUSER=$this->db->username;
$DBPASSWD=$this->db->password;
$DATABASE=$this->db->database;

$filename = $DATABASE . "-" . date("Y-m-d_H-i-s") . ".sql.gz";
$mime = "application/x-gzip";

header( "Content-Type: " . $mime );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );

// $cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";
$cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";

// Instead of the above command, I have tried the following command to save to the server but it didn't save
// $save_path = $_SERVER['DOCUMENT_ROOT'] . '/application/assets/db_backups/' . $filename;
// $cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best > " . $save_path;

passthru( $cmd );

我想要的是,将其保存在服务器上,而不是推送给用户。我如何修改它以使文件下载到服务器上?

最佳答案

我修改了我的代码如下,它起作用了

$DBUSER=$this->db->username;
$DBPASSWD=$this->db->password;
$DATABASE=$this->db->database;

$filename = $DATABASE . "-" . date("Y-m-d_H-i-s") . ".sql.gz";

$save_path = $_SERVER['DOCUMENT_ROOT'] . '/application/assets/db_backups/' . $filename;
$cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best > " . $save_path;

exec( $cmd );

关于php - 将数据库备份保存在服务器上而不是推送给用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24135888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com