我正在使用我的 PHP 将文件存储在数组中。现在我想从阵列下载文件。当我尝试这个时:if($attachments[$attach_id]){ $filename = $attachments[$attach_id]['name']; $attachment = $attachments[$attach_id]['attachment']; header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=".basename($attachment)); echo readfile($attachment);}它不会从数组中提取文件让我下载文件。这是完整的代码:<?phprequire_once "Mail.php";require_once('Mail/IMAPv2.php');$username = 'username';$password = 'password';$mailserver = '{imap.domain.com:993/imap/ssl/novalidate-cert}INBOX';$mailbox = imap_open($mailserver, $username, $password) or die("Can't connect: " . imap_last_error());$key = "key";$email_number = "279";$attach_id = '1';echo "hello!";/* get information specific to this email */$overview = imap_fetch_overview($mailbox, $email_number, 0);$message = imap_fetchbody($mailbox, $email_number, 2);/* get mail structure */$structure = imap_fetchstructure($mailbox, $email_number);$attachments = array();$attachment_number = 0;当我存储它们时,如何从阵列中下载文件?我是否必须先输出它们,或者是否有办法提取然后下载它?我没有将文件存储在服务器上,因为我想使用 id 从电子邮件中下载附件。
1 回答
波斯汪
TA贡献1811条经验 获得超4个赞
代替:
header("Content-Type: application/octet-stream");
和:
header("Content-Type: ".mime_content_type($attachment));
这是因为Content-Type: application/octet-stream
. 使用mime_content_type()
找到合适的MIME类型。
- 1 回答
- 0 关注
- 116 浏览
添加回答
举报
0/150
提交
取消