我正在用php创建一个恢复数据库的脚本,但它不起作用。这是到目前为止的代码
<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);
}
?>
单击还原按钮后未发生任何反应。请帮帮忙
发布于 2013-03-04 14:51:56
$restore = "c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name";
^^^^^^^^^^^
你在任何地方都无法定义$backup_name
。难道不应该是$restore_name
吗?
上传也不会出现在$_POST
中。他们通过$_FILES
出现。
你也不应该假设上传成功。尤其是对于mysql转储文件。有可能上传被截断了,但您盲目地将文件返回到MySQL,这可能会给您留下一个部分/完全垃圾的数据库。
ALWAYS检查上载错误:
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
https://stackoverflow.com/questions/15204268
复制相似问题