Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试使用mysqldump和exec进行数据库备份时打开流失败错误_Php_Exec_Mysqldump - Fatal编程技术网

Php 尝试使用mysqldump和exec进行数据库备份时打开流失败错误

Php 尝试使用mysqldump和exec进行数据库备份时打开流失败错误,php,exec,mysqldump,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); $messag

通过以下代码,我得到警告:文件(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);
?> 
$command=“mysqldump-u$dbuser-h localhost--password=$dbpwd$dbname | gzip>$filename”;
exec($command);
如果($sendmail)
{
$attachmentname=basename($filename);
$message=“压缩数据库备份文件$attachmentname已附加。”;

$mime\u boundary=“可能您没有对尝试创建
$filename
的目录的写入权限。不相关的问题,但您可能不应该对压缩文件使用
文件()
,它用于读取文本文件。使用
文件获取内容()
。你可能想使用第三方邮件工具,如PHPMailer或SwiftMailer。组装你自己的MIME邮件头是愚蠢的。@Barmar如果我使目录可写,为网站供电的CMS会抛出404,切换回755,我会再次收到上面的错误。然后你需要写入其他目录,如/tmp。