Php 邮件问题中的Zip文件附件

Php 邮件问题中的Zip文件附件,php,email-attachments,ziparchive,Php,Email Attachments,Ziparchive,我正在尝试使用phpMailer发送包含CSV文件的zip附件邮件 但当我执行时,我会在指定的位置和邮件中获取zip文件,但在这两个位置我都无法提取CSV文件,它表示CRC失败,文件已损坏 谁能告诉我解决办法吗 <?php $zip = new ZipArchive(); $now = new DateTime(); $info = pathinfo($filename); $name = $info['filename']; $ext = $info['extension']; $

我正在尝试使用phpMailer发送包含CSV文件的zip附件邮件

但当我执行时,我会在指定的位置和邮件中获取zip文件,但在这两个位置我都无法提取CSV文件,它表示CRC失败,文件已损坏

谁能告诉我解决办法吗

<?php

$zip = new ZipArchive();
$now = new DateTime();

$info = pathinfo($filename);
$name = $info['filename'];
$ext = $info['extension'];

$time = "download.zip";
$pathto = "images/importcsv/download.zip";
$res = $zip->open($pathto, ZipArchive::CREATE);
if ($res == true) {
    $zip->addFile($filename, substr($filename, strrpos($filename, '/') + 1));
}

$zip->close();

yii::import('application.extensions.smtpmail.PHPMailer');
$mail = new PHPMailer();
$mail->Host = $dmmodel->host;
$mail->Username = $dmmodel->username;
$mail->Password = $dmmodel->password;
$mail->Mailer = 'smtp';
$mail->Port = $dmmodel->port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ($dmmodel->smtp_enableSSL == 1 ? 'ssl' : ($dmmodel->smtp_enableSSL == 2 ? 'tls' : ''));

$mail->From = $dmmodel->email_from;
$mail->FromName = $dmmodel->name_from;

$mail->Subject = "Cron Export CSV";
$mail->MsgHTML("Cron Export CSV");
$mail->AddAddress($dmmodel->default_TO, "");
$mail->AddAttachment("images/importcsv/download.zip", "download.zip");
if (!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

images/importsv/download.zip是否已在服务器上损坏或仅在邮件中损坏?在服务器上已损坏。下面是zip错误标志,它们只是整数。如果使用$res==true进行检查,则任何整数都将为true!=0; 因此,您应该使用$res==true进行检查,或者如果它是int,则检查它对应的错误