Menu

#3004 (ok 3.3.2) Excel 97-2003 exports and temporary directory

3.3.1
fixed
1
2014-07-03
2010-03-19
No

When attempting an Excel 97-2003 XLS Woorkbook export, one gets:

[Fri Mar 19 15:55:41 2010] [error] [client 130.238.131.137] PHP Fatal error: Uncaught exception 'Exception' with message 'Can't create temporary file' in /apache/htdocs/hotel/phpMyAdmin-3.3.1-all-languages/libraries/PHPExcel/PHPExcel/Shared/OLE/OLE_File.php:98\nStack trace:\n#0 /apache/htdocs/hotel/phpMyAdmin-3.3.1-all-languages/libraries/PHPExcel/PHPExcel/Writer/Excel5.php(190): PHPExcel_Shared_OLE_PPS_File->init()\n#1 /apache/htdocs/hotel/phpMyAdmin-3.3.1-all-languages/libraries/export/xls.php(62): PHPExcel_Writer_Excel5->save('/tmp/pma_xls_mZ...')\n#2 /apache/htdocs/hotel/phpMyAdmin-3.3.1-all-languages/export.php(568): PMA_exportFooter()\n#3 {main}\n thrown in /apache/htdocs/hotel/phpMyAdmin-3.3.1-all-languages/libraries/PHPExcel/PHPExcel/Shared/OLE/OLE_File.php on line 98

It appears that a temporary file was created, but with zero size, listing /tmp:

-rw------- 1 web web 0 2010-03-19 15:55 pma_xls_mZmeaz

The zero size file is most probably generated by _initialize() in libraries/PHPExcel/PHPExcel/Writer/Excel5/Worksheet.php, which is called by save() in libraries/PHPExcel/PHPExcel/Writer/Excel5.php.

However, the latter function also (later) calls $OLE->init(), which in init() in libraries/PHPExcel/PHPExcel/Shared/OLE/OLE_File.php will attempt to fopen() a temporary file (not necessarily the same!). The temporary file name is composed of a tempnam() call specifying $this->_tmp_dir as the directory, but as phpMyAdmin doesn't seem to have called $OLE->setTempDir(), the directory is empty, The outcome of that is supposedly undefined (the PHP docs for tempnam() only mentions that " If PHP cannot create a file in the specified dir parameter, it falls back on the system default." which may differ, and in our case (on our platform), seems to be broken: http://bugs.php.net/bug.php?id=42560

The best way to solve this (awaiting the PHP fix for our platform) would be to make sure that phpMyAdmin calls setTempDir to make sure that the temporary directory for PHPExcel is always explicitly set to the same value as $cfg['TempDir'] of the phpMyAdmin configuration.

Attaching a diff for libraries/export/xls.php for that.

Discussion

  • Björn Wiberg

    Björn Wiberg - 2010-03-19

    libraries/export/xls.php patch to set temporary directory

     
  • Michal Čihař

    Michal Čihař - 2010-03-31
    • assigned_to: nobody --> nijel
     
  • Michal Čihař

    Michal Čihař - 2010-03-31

    Patch merged in git, thanks for your contribution!

     
  • Michal Čihař

    Michal Čihař - 2010-03-31
    • priority: 5 --> 1
    • summary: Excel 97-2003 exports and temporary directory --> (ok 3.3.2) Excel 97-2003 exports and temporary directory
     
  • Marc Delisle

    Marc Delisle - 2010-04-14
    • status: open --> closed
     
  • Michal Čihař

    Michal Čihař - 2013-06-11
    • Status: closed --> fixed
     
MongoDB Logo MongoDB