【发布时间】:2011-06-07 18:11:40
【问题描述】:
我正在使用 PHP 动态创建 CSV,然后我需要将此 CSV 文件附加到 Swift Mailer Message。我尝试在创建的文件上使用 file_get_content 以及在创建的文件上使用 chunk_split(base64_encode(file_get_contents()) 以及在将文件写入磁盘之前附加文件。不写入磁盘我在 CSV 中得到 Resource #183,并附加使用 file_get_content 我在 CSV 文件的每一行中只得到一个字符串,有人知道我在做什么错吗?
if(!file_exists(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv'))
{
if($file = fopen (_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv', 'x+'))
{
foreach ($list as $fields)
{
fputcsv($file, $fields);
}
$attachment['mime'] = 'application/vnd.ms-excel';
$attachment['content'] = file_get_contents($file);
$attachment['name'] = $order.'order';
EDIT
Mail::Send(1, 'order_conf', 'Order CSV Attachment', $success, 'test@email.com', Address, NULL, NULL, $attachment); // attach and send
}
}
【问题讨论】:
-
你能显示你用来附加附件的代码吗?
-
“CSV 文件的每一行中都有一个字符串”是什么意思?
-
我可以很好地创建文件,但发送它时遇到问题。我的意思是,不是将数组中的每个项目分配给行中的单独单元格,而是第一行(例如 A1)将包含数组中的所有值,用逗号分隔
-
您可能想要关闭 $file 并取消设置它...只需 file_get_contents(PS_ORDERS_DIR.$orderDate.'/'.$file_name.'.csv')而不是 file_get_contents($file); ?
标签: php csv attachment swiftmailer mailer