phpspreadsheet does not save the xlsx file to server

0

I publish this question, because I have really searched a lot in the documentation of PHPSpreadsheet (successor of PHPExcel), in forums, in examples, etc ... and I have not found a solution to my problem, I put the panorama:

I wrote a code to "export" the contents of a database to an excel according to a personalized search (the search works well), my tests are executed using XAMPP and once tested and released, I upload them to the server LAMP, both (XAMPP and LAMP) have the same versions of PHP and MySQL. However, the script works perfectly when it runs on XAMPP, but when I upload it to the server the script does not save the excel anywhere, but it does not give me errors at all. To prove that it was not a coding error, I developed the small code that I show below, where I perform tests to see the scope of variables, routes, declarations, etc ... Similarly, on XAMPP the script generates the file: archivuenew.xlxs , but on the Linux server, nothing is written or saved. The code gives me the following output:

  

Load Xlsx: IOFactory PASSED
Get & Set Cell Value:   setCellValue PASSED
New Xlsx: Xlsx
  PASSED
Saving File to Local: save PASSED
  ALL TASKS PASSED: OK

<?php

header('Content-type: text/plain');
error_reporting(E_ALL);
ini_set('display_errors','1');

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load("template.xlsx");
echo "\n Load Xlsx:            IOFactory      PASSED";

$spreadsheet->getActiveSheet()->setCellValue('A1', 'Esto es una prueba!');
echo "\n Get & Set Cell Value: setCellValue   PASSED";

$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
echo "\n New Xlsx:             Xlsx           PASSED";

$writer->save('archivonuevo.xlsx');
echo "\n Saving File to Local: save           PASSED";

echo "\n \n \n ALL TASKS PASSED: OK";

?>

If I put the options of:

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="archivonuevo.xlsx"');
$writer->save("php://output");

the file is written correctly, but it does not save it, but it shows it directly for download (something that does not work for me) because the application requires that the file be generated and saved in a location so that the user can download it later if he wants it. Which confirms that the problem is not in the routes of the "use" directive or the calls to "PhpOffice \ PhpSpreadsheet \ IOFactory ::" but in the save () function.

If someone has an idea that could help me, I would really appreciate it. I think it's on the permissions side, I do not know if Apache is blocking executions and writing files to the server, I do not know if the related files should have a special permission, I already tried putting the permissions of the folder (only for try) to 777 but still does not save anything either, the user who runs Apache is the same one who owns the folders where the script is executed and where the file must be saved.

Thanks for the help.

    
asked by imux98 19.07.2018 в 01:30
source

0 answers