Welcome Guest, Not a member yet? Register   Sign In
Attach binary file via Email class right from MySQL database
#1

[eluser]andyy[/eluser]
I'm looking to attach a binary file (.pdf) to an e-mail right from a MySQL database using the Email class. I'm trying to avoid writing the MySQL binary store to a flat file in a specified directory and then attaching it (but I may have no choice).

Code:
$this->load->library('email');
$this->load->model('Some_model');

$this->email->to('[email protected]');
$this->email->from('[email protected]');

$this->email->subject('Your PDF File');
$this->email->message('Your PDF is attached to this e-mail.');

$this->email->attach($this->Some_model->getPdf() );

$this->email->send();

Anyone want to provide some insight into this?

Thanks.
#2

[eluser]adityamenon[/eluser]
Are you storing the pdf binary data directly inside the MySQL db? Is this a necessity? Most people simply store the pdf inside a folder on the server, and only remember the file name with a database. This saves DB disk space...which is more precious than file-system disk space... and will make your MySQL queries faster since the DB engine doesn't have to wade through tons of crazy pdf characters every time it needs to do a select.

If it is a necessity, however, then yes, your line of thought is correct. I think there's no other way but to write the pdf data from your DB into a temp file and attach that file.




Theme © iAndrew 2016 - Forum software by © MyBB