簡體   English   中英

CSV file_get_contents發送PHP

[英]CSV file_get_contents sending PHP

我正在嘗試使用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;
        }

如果您使用的是Swift Mailer,則不需要file_get_contents() ,您可以直接附加文件

從Swift Mailer文檔中:

//Create the attachment
// * Note that you can technically leave the content-type parameter out
$attachment = Swift_Attachment::fromPath('/path/to/image.jpg', 'image/jpeg');  

//Attach it to the message
$message->attach($attachment);

因此,對您而言,這將是:

$attachment = Swift_Attachment::fromPath(_PS_ORDERS_DIR_.$orderDate.'/'.$file_name.'.csv', 'application/vnd.ms-excel');  

//Attach it to the message
$message->attach($attachment);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM