phpxltmp*.xlsx temporary files

Apr 6, 2011 at 1:27 PM
Edited Apr 6, 2011 at 1:39 PM



Im searching for a solution to change the directory of the temporary created files from php excel.

At the moment they will saved into the root directory of the project.


"$objPHPExcel = new PHPExcel();" is the object where i fill my stuff into the excel sheet.

as writer obj ill use "$objWriter =PHPExcel_IOFactory::createWriter($oPHPExcel, $sExcelType)"; (execltype = Excel2007)

if i execute the "$objWriter->setTempDir('/path/to/temp/')" the script will give me the error: "Fatal error: Call to undefined method PHPExcel_Writer_Excel2007::setTempDir()"

without the thempdir method it will create my excelfile without problems, but sometimes there will be some phpxltmp*****.xlsx files in the root.

is there a solution to set the direcotry for those temporary files into an user-defined directory?


ill use:

 * @category   PHPExcel
 * @package    PHPExcel
 * @version    1.7.0, 2009-08-10



Apr 7, 2011 at 2:48 PM

There seems no user-defined soultion for.

tmp files will always created in root directory. as i see in code of php excel.

ill build a small workaround:

save file on specified folder "$objWriter('/path/to/temp/file.tmp')" and send it to the user with $rFile = fopen('/path/to/temp/file.tmp', 'r'), header(...), fpassthru($rFile).

thx anyways

Apr 7, 2011 at 11:26 PM


$objWriter->setUseDiskCaching(true, '/path/to/temp/');
Apr 8, 2011 at 6:08 AM
Edited Apr 8, 2011 at 6:12 AM


thx for your answer!


In a short lookup at the code, ill find no usage of this variable "_diskCachingDirectory".

its possible to set the directory, and it will be set, but i dont see that it will be used for save method.


this is a snippet from class PHPExcel_Writer_Excel2007 -> save() method of version  1.7.3c, 2010-06-01:


// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
    $pFilename = @tempnam('./', 'phpxltmp');
    if ($pFilename == '') {
        $pFilename = $originalFilename;

in my first case i used "php://output" as argument in save method.

as u can see, there will be always set "./" as directory for the temp file - maybe this is solved in following versions of phpexcel. (or im dump and dont check the right code, or associated it wrong)

at the end of the save method, he will unlink the temp file - so my (core-)problem seems to be an interrupt of script, while outputing the file.

anyways, we temporary do not use excel export for the moment..


Apr 8, 2011 at 8:41 AM

It's not impossible that there are errors in the code, and places where it is incorrectly used, and the specified temp directory should probably be used in the case you've cited.

But there are plenty of blocks within the code where this is used.

The _diskCachingDirectory property is retrieved using the $objWriter->getDiskCachingDirectory(); method, and a quick search of the code shows that this is being referenced in the Comments, ContentTypes, DocProps, Drawing, Rels, StringTable, Style, Theme, WorkBook and WorkSheet classes used by the Excel2007 Writer.

That one hardcoded reference to ./ appears to be the only one that exists in the Excel2007 Writer. You can modify it to:

// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
   $pFilename = @tempnam($this->getDiskCachingDirectory(), 'phpxltmp');
   if ($pFilename == '') {
      $pFilename = $originalFilename;
Jul 26, 2011 at 8:10 PM

I also hit the problem with the './' being used as temporary directory by the Excel2007 Writer. the modification works fine, I hope this change will be added to the next release.