sys_get_temp_dir() requires PHP 5.2.1, not PHP 5.2

Topics: Developer Forum, Project Management Forum
Nov 19, 2009 at 6:14 PM


This is my environment:

  • PHPExcel 1.7.1
  • PHP 5.2.0
  • Windows 2000 Advanced Server

The install.txt file included with PHPExcel indicates that PHP version 5.2 is required. However, when I try to create an Excel 5 workbook on this system, I get this PHP error.

<b>Fatal error</b>:  Call to undefined function sys_get_temp_dir() in <b>G:\Web Files\YUI\PHPExcel\Classes\PHPExcel\Writer\Excel5.php</b> on line <b>133</b><br />

I looked at sys_get_temp_dir() in the PHP manual (, and sure enough, it requires PHP 5.2.1. So you might want to update the install.txt file to indicate PHP 5.2.1 or higher is required.


Nov 20, 2009 at 7:23 AM
Edited Nov 20, 2009 at 7:25 AM

Woops... You are quite right. Instead of requiring PHP 5.2.1 a workaround has now been incorporated like in comment:

To avoid confusion the install.txt has also been updated so it now says "PHP version 5.2.0 or higher" instead of just "PHP version 5.2 or higher".

Can you check in a couple of hours with latest source code that things are working correctly on PHP 5.2.0 ? Thanks for reporting this.

Latest source code:

Mar 1, 2010 at 7:12 PM

If you can't upgrade your php version you can implement this function:

 if ( !function_exists('sys_get_temp_dir')) {
  function sys_get_temp_dir() {
      if( $temp=getenv('TMP') )        return $temp;
      if( $temp=getenv('TEMP') )        return $temp;
      if( $temp=getenv('TMPDIR') )    return $temp;
      if (file_exists($temp)) {
          return dirname($temp);
      return null;

 echo realpath(sys_get_temp_dir());

I did this in my server with php 5.1.26 and worked fine.

Source of code: