【发布时间】:2011-01-12 13:28:43
【问题描述】:
我正在尝试使用 PHP 发送一个 .CSV 文件。该文件在发送之前已写入磁盘,但是当我尝试使用 file_get_contents() 附加文件时;当尝试发送在发送之前创建的文件时,.CSV 的结构还没有被保留,我得到一个资源 ID (#183) 那么我如何附加一个用户可以作为 .CSV 文件打开的文件?我已确保 mime 类型和标题正确
编辑
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(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv');
$attachment['name'] = $order.'order';
Mail::Send(1, 'order_conf', 'Order CSV Attachment', $success, 'dan.farr@gmail.com', CakeToppers, NULL, NULL, $attachment);
return true;
}
【问题讨论】:
-
我认为问题不在于
file_get_contents()。您如何添加文件并发送消息? -
我正在使用 Swift Mailer 发送电子邮件。我记得我不久前使用 file_get_contents() 或 fopen() 或类似的东西得到了这个工作,但我已经尝试了将它们与字符串和资源一起使用的所有组合,但没有运气。我知道 CSV 文件已成功创建,因为创建后我可以查看它们,所以我不知所措。
-
请贴一些代码。看起来您正在使用一个作为处理程序的变量
标签: php csv file-get-contents