2011-01-12 4 views
1

PHP로 .CSV 파일을 보내려고합니다. 파일이 전송되기 전에 디스크에 기록되지만 file_get_contents()로 파일을 첨부하려고하면 파일이 작성됩니다. .CSV의 구조는 보내지 전에 생성 된 파일을 보내고 보낼 때 자원 ID (# 183)를 얻습니다. 그래서 사용자가 .CSV 파일로 열 수있는 파일을 첨부 할 수 있습니까? 나는 MIME 타입 확인했습니다 및 헤더는 스위프트 메일러를 사용하는 경우, file_get_contents()에 대한 필요가, 당신은 단지 attach the file directly을 할 수 없습니다CSV file_get_contents PHP를 전송

편집

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, '[email protected]', CakeToppers, NULL, NULL, $attachment); 
    return true; 
     } 
+2

나는 문제가'file_get_contents 생각하지는()'. 어떻게 파일을 추가하고 메시지를 보내고 있습니까? – jeroen

+4

몇 가지 코드를 보여줄 수 있습니까? –

+0

저는 Swift Mailer를 사용하여 이메일을 보내고 있습니다. 나는 이전에 file_get_contents() 또는 fopen() 또는 그와 유사한 것을 사용하여 잠시 동안이 작업을 수행했음을 기억하지만 문자열과 자원을 사용하지만 운이없는 모든 조합을 시도했습니다. CSV 파일이 만들어지면 볼 수 있기 때문에 CSV 파일이 성공적으로 만들어지고 있다는 것을 알고 있습니다. – Dan

답변

1

정확합니다. 스위프트 메일러 문서에서

:

//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);