0

for my project I'm using PHPSpreadsheet for exporting data in Excel and PDF format. If from the website, when I press on the respective download buttons, I can easily download the .xlsx and .pdf files, I have problems with the app (iOs Swift language). In fact, when I try to download the files, I receive the following messages:

  • for Excel files: "the file may be damaged"
  • for PDF files (I open it with Chrome): "Chrome does not support this link file: ///var/mobile/Containers/Data/Application/.../Documents/name_file.pdf"

Here are the fragments of the PHP code that deal with the download:

PDF:

$ output. = '... html code';
$ mpdf = new \ Mpdf \ Mpdf ();
$ mpdf-> Bookmark ('Start of the document');
$ Mpdf-> WriteHTML ($ output);
$ mpdf-> Output ($ filename.'. pdf', 
\Mpdf\Output\Destination::DOWNLOAD);

EXCEL:

$spreadsheet = new Spreadsheet();  /*----Spreadsheet object-----*/
$Excel_writer = new Xlsx($spreadsheet);  /*----- Excel (Xls) Object*/

/* ...riempiendo foglio excel con i dati */

header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: 
attachment;filename="'.$filename.'.xlsx"');
header('Cache-Control: max-age=0');
$Excel_writer->save('php://output');

Thanks for your help!

ivan2_88
  • 1
  • 4

1 Answers1

0

for Excel files: "the file may be damaged"

My blind guess is that when you peek the file content you will find Headers already sent PHP message polluting your file. If that is so, just call ob_start() before you call any of your header()s.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141