Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: wygenerowany PDF, zapis
Forum PHP.pl > Forum > PHP
misiek172
Witam.

Wygenerowałem PDFa dzieki bibliotece FPDF i chcialbym go oprocz wyswietlenia zapisac na serwerze, jak to zrobic?

Pozdrawiam, Lukasz.
bim2
Może pokaż jak go wyświetlasz? smile.gif
misiek172
jak to jak wyswietlam? $pdf->Output();
bartg
  1. <?php
  2. $pdf->Output()
  3. $result = ob_get_contents();;
  4. ?>

I zawartość $result zapisujesz do pliku winksmiley.jpg.

Chyba że istnieje jakaś funkcja w tej klasie smile.gif

DOWN: No właśnie, istnieje biggrin.gif
bim2
No to
$pdf -> Output($filename,$dir);
misiek172
to moze jakos przerobic te funkcje Output?
bartg
Nie rozumiem, przecież bim podał gotowe rozwiązanie.
misiek172
bo nie czytal manuala, ze ta funkcja ma inna konstrukcje

http://www.fpdf.org/en/doc/output.htm
bim2
http://www.google.com/search?q=fpdf+save&a...lient=firefox-a

Pierwszy wynik.

Ups, przepraszam ja nie doczytałem.
  1. <?php
  2. function Output($name='',$dest='')
  3. {
  4. //Output PDF to some destination
  5. //Finish document if necessary
  6. if($this->state<3)
  7. $this->Close();
  8. //Normalize parameters
  9. if(is_bool($dest))
  10. $dest=$dest ? 'D' : 'F';
  11. $dest=strtoupper($dest);
  12. if($dest=='')
  13. {
  14. if($name=='')
  15. {
  16. $name='doc.pdf';
  17. $dest='I';
  18. }
  19. else
  20. $dest='F';
  21. }
  22. switch($dest)
  23. {
  24. case 'I':
  25. //Send to standard output
  26. $this->Error('Some data has already been output, can't send PDF file');
  27. if(php_sapi_name()!='cli')
  28. {
  29. //We send to a browser
  30. header('Content-Type: application/pdf');
  31. $this->Error('Some data has already been output to browser, can't send PDF file');
  32. header('Content-Length: '.strlen($this->buffer));
  33. header('Content-disposition: inline; filename="'.$name.'"');
  34. }
  35. echo $this->buffer;
  36. break;
  37. case 'D':
  38. //Download file
  39. $this->Error('Some data has already been output, can't send PDF file');
  40. if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  41. header('Content-Type: application/force-download');
  42.  else
  43. header('Content-Type: application/octet-stream');
  44. $this->Error('Some data has already been output to browser, can't send PDF file');
  45. header('Content-Length: '.strlen($this->buffer));
  46. header('Content-disposition: attachment; filename="'.$name.'"');
  47. echo $this->buffer;
  48. break;
  49. case 'F':
  50. //Save to local file
  51. $f=fopen($name,'wb');
  52. if(!$f)
  53. $this->Error('Unable to create output file: '.$name);
  54. fwrite($f,$this->buffer,strlen($this->buffer));
  55. fclose($f);
  56. break;
  57. case 'S':
  58. //Return as a string
  59. return $this->buffer;
  60. default:
  61. $this->Error('Incorrect output destination: '.$dest);
  62. }
  63. return '';
  64. }
  65. ?>
misiek172
a jakbym aby jednocześnie sie zapisało i wyświetlilo?
bartg
Wywołać 2x funkcje Output? Możliwe że zaskoczy
misiek172
nie poniewaz wyskoczy blad ze header alerdy send
bim2
$this->Output('adres do pliku itd', 'F'); //To nie wysyła żadnych nagłówków...
$this->Output();
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.