尝试使用mysqldump和exec进行数据库备份时,无法打开流错误

时间:2012-12-23 08:19:14

标签: php exec mysqldump

使用以下代码我得到警告:文件(filename.sql.gz)[function.file]:无法打开流:没有这样的文件或目录。我做错了什么?

$command = "mysqldump -u $dbuser -h localhost --password=$dbpwd $dbname | gzip > $filename";
exec($command);

if ($sendEmail)
{
$attachmentname = basename($filename);

$message = "Compressed database backup file $attachmentname attached.";
$mime_boundary = "<<<:" . md5(time());
$data = chunk_split(base64_encode(implode("", file($filename))));

$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= " boundary=\"$mime_boundary\"\r\n";

$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--$mime_boundary\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $message."\r\n";
$content.= "--$mime_boundary\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--$mime_boundary\r\n";

mail($to, $subject, $content, $headers);
}

if (!$keepFile) unlink($filename);
?> 

0 个答案:

没有答案