php - CodeIgniter rename email attachment file -
i have codeigniter script sending email attachments.
$this->ci->email->attach("/path/to/file/myjhxvbxhjdsycv1y.pdf"); it works great, have no idea, how rename attached file more user-friendly string?
codeigniter v3.x
this feature has been added since ci v3:
/** * assign file attachments * * @param string $file can local path, url or buffered content * @param string $disposition = 'attachment' * @param string $newname = null * @param string $mime = '' * @return ci_email */ public function attach($file, $disposition = '', $newname = null, $mime = '') according user guide:
if you’d use custom file name, can use third parameter:
$this->email->attach('filename.pdf', 'attachment', 'report.pdf');
codeigniter v2.x
however codeigniter v2.x, can extend email library implement that:
- create copy of
system/libraries/email.php, put insideapplication/libraries/ - rename file , add
my_prefix (or whatever have set inconfig.php)application/libraries/my_email.php - open file , change following:
first: insert @ line #72:
var $_attach_new_name = array(); second: change code @ line #161-166 to:
if ($clear_attachments !== false) { $this->_attach_new_name = array(); $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); } third: find attach() function @ line #409 , change to:
public function attach($filename, $disposition = 'attachment', $new_name = null) { $this->_attach_new_name[] = $new_name; $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(pathinfo($filename, pathinfo_extension)); $this->_attach_disp[] = $disposition; // can 'inline' not sure if matters return $this; } fourth: @ line #1143 change code to:
$basename = ($this->_attach_new_name[$i] === null) ? basename($filename) : $this->_attach_new_name[$i]; usage
$this->email->attach('/path/to/filename.ext', 'attachment', 'newfilename.ext');
Comments
Post a Comment