2

I am currently working on a project that has files stored in a DB as blobs. I need to attach the file to an e-mail and send it out via PHPMailer. I am familiar with $mail->addAttachment(), however, this function seems to take in a file path only, which I don't have. I was wondering if there is any way to manipulate the blob and feed to this function ?

I appreciate any suggestions, thanks in advance!

The following successfully creates a 'Save As' dialog of the file I need to attach:

header("Content-disposition: attachment; filename={$filename}.{$file_ext}");
header("Content-type: application/octet-stream");
echo $pdf['data'];
exit;
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
  • The most obvious solution is to save the blob to a file. – Musa Jul 05 '14 at 03:42
  • Musa, thanks for the reply, yes, I was thinking: Save the file, attached the file, send the e-mail, then delete the file. However, seems a bit overkill. If there isn't a more straightforward direct solution, thats the one i'll go with. – AnchovyLegend Jul 05 '14 at 06:55

1 Answers1

4

The addStringAttachment method is capable of handling such case. According to its doc:

* Add a string or binary attachment (non-filesystem).
* This method can be used to attach ascii or binary data,
* such as a BLOB record from a database.
T30
  • 11,422
  • 7
  • 53
  • 57
Synchro
  • 35,538
  • 15
  • 81
  • 104