0

I am using a free extension of opencart which allows me to download invoice in PDF to my local system (Downloads folder).

I want two things to happen

  1. I want to download PDF file in my root. (if I am working on localhost I want the file to download in root\abc\ )

  2. The other thing i want is that there is an email textbox and email button what I want is that I want to send email to user(eAddress written in textbox) with auto attachment of that downloaded pdf file located in(root\abc)

CODE :

$pdf = (isset($this->request->get['pdf'])) ? true : false;
$eFlag= (isset($this->request->get['email'])) ? true : false;

if ($pdf){
$this->response->setOutput(pdf($this->render(),$this->data['orders']));
}
elseif ($eFlag) {
$fp = fopen(DIR_DOWNLOAD . "meeru.pdf","wb");
$dataHtml = $this->render();
$name = $this->data['orders'];
if (count($name) > 1) {
$name = "Orders";
}else{
$name = 'Order_'.$name[0]['order_id'];
}
$pdf = new DOMPDF;
$pdf->load_html($dataHtml );
$pdf->render();
fwrite($fp , $pdf->output( array("compress" => 0) ));
fclose($fp );
$this->response->setOutput("File Saved");
}
else{
$this->response->setOutput($this->render());
}

Its downloading just one time (for the first time in root/download)

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Ammar Ul Hassan
  • 826
  • 1
  • 18
  • 48
  • That seems to indicate your code doesn't have writing permissions in the folder you want to output to, no? Have you checked permissions in that folder? In that php code, have you tried to create a simple text file in that same folder to see whether that would even work? – David van Driessche May 14 '15 at 13:24
  • @DavidvanDriessche please review my edits in question i have loaded the code which i have done for writing in specific file – Ammar Ul Hassan May 14 '15 at 13:44
  • I think you need to clean up your code first if you want any chance on success. If $name has no elements, your code is going to use the first element in it. That doesn't seem right. You have a "$filename" variable that as far as I can see isn't used. If you're getting a blank page, more than likely you have a PHP error, so you should check your PHP error log to find out which part of this code throws an error and what it is. – David van Driessche May 14 '15 at 16:37
  • Also, why do you specify base64_decode? $pdf->output() should give you the whole PDF file as a string and you can just dump it in a file... – David van Driessche May 14 '15 at 16:40
  • You might have an error, or you might just not be sending anything to the browser. At least it doesn't look like it based on the little code you provided. Does the file appear in the location you specified? If you actually want to view the PDF in the browser you'll still need to send it. You could try calling `$dompdf->stream()` after you write the file to your filesystem or (if the file you write out is accessible via the web server) just redirect the user to that file. At the very least you should echo something to the client. Maybe you are, but we can't tell from what you've provided. – BrianS May 14 '15 at 18:01
  • Also, you might want to ask your email question separately. First, however, [search on stackoverflow](http://stackoverflow.com/search?q=[dompdf]+email) as the question has been asked before. E.g. http://stackoverflow.com/q/7958416/264628 – BrianS May 14 '15 at 18:03
  • @BrianSactually i want to download file in my root/download directory i dont want to show any thing in browser. after downloading i want to send email the respective file as attachment to user – Ammar Ul Hassan May 15 '15 at 06:17
  • @BrianS some how i have manage to download my pdf in my root/download by integrating different threads. but the problem is that it only downloads once i.e just one time. please review my code above and give me suggestions. – Ammar Ul Hassan May 15 '15 at 06:39
  • @DavidvanDriessche some how i have manage to download my pdf in my root/download by integrating different threads. but the problem is that it only downloads once i.e just one time. please review my code above and give me suggestions. – Ammar Ul Hassan May 15 '15 at 06:39
  • For email you should first take a look at the questions that have already been asked on that topic (per my earlier comment). – BrianS May 16 '15 at 03:46

0 Answers0