我正在使用我的 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);
}
它不会从数组中提取文件让我下载文件。
这是完整的代码:
<?php
require_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 从电子邮件中下载附件。
波斯汪