From 104460ae3eca1e1d53ad5e4541d076c967421c1c Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sat, 29 Aug 2015 11:32:32 +0200 Subject: [PATCH] PDF documents sent by email have now meaningful names. --- reporting/includes/class.mail.inc | 13 ++++++++----- reporting/includes/pdf_report.inc | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/reporting/includes/class.mail.inc b/reporting/includes/class.mail.inc index 7cce85a1..26a109fd 100644 --- a/reporting/includes/class.mail.inc +++ b/reporting/includes/class.mail.inc @@ -65,9 +65,11 @@ class email $this->bcc[] = $mail; } - function attachment($file) + function attachment($file, $filename=null) { - $this->attachment[] = $file; + if (!isset($filename)) + $filename = basename($file); + $this->attachment[$filename] = $file; } function subject($subject) @@ -130,12 +132,13 @@ class email if ($max > 0) { for ($i = 0; $i < $max; $i++) + foreach ($this->attachment as $filename => $file) { - $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i])); + $file = fread(fopen($file, "r"), filesize($file)); $this->body .= "--".$this->boundary."\n"; - $this->body .= "Content-Type: " .$this->mime_type(basename($this->attachment[$i])). "; name=\"".basename($this->attachment[$i])."\"\n"; + $this->body .= "Content-Type: " .$this->mime_type($file). "; name=\"".$filename."\"\n"; $this->body .= "Content-Transfer-Encoding: base64\n"; - $this->body .= "Content-Disposition: attachment; filename=\"".basename($this->attachment[$i])."\"\n\n"; + $this->body .= "Content-Disposition: attachment; filename=\"".$filename."\"\n\n"; $this->body .= chunk_split(base64_encode($file),"72","\n"); $file = ""; } diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index c8bd3255..9e96bf2c 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -969,10 +969,10 @@ class FrontReport extends Cpdf } // do not use standard filenames or your sensitive company data // are world readable - if ($email == 1) - $fname = $dir.'/'.$this->filename; - else - $fname = $dir.'/'.uniqid('').'.pdf'; +// if ($email == 1) +// $fname = $dir.'/'.$this->filename; +// else + $fname = $dir.'/'.uniqid('').'.pdf'; $this->Output($fname, 'F'); if ($email == 1) @@ -1026,7 +1026,7 @@ class FrontReport extends Cpdf $mail->to($to); $try++; $mail->subject($subject); $mail->text($msg . $sender); - $mail->attachment($fname); + $mail->attachment($fname, $this->filename); $emails .= " " . $contact['email']; if ($mail->send()) $sent++; } // foreach contact -- 2.30.2