-4

任何人都知道PHP中sys_get_temp_dirandDIRECTORY_SEPARATOR的替代函数tempnam

现有的 PHP 版本是 4.*

4

1 回答 1

1

tempnam 存在于 PHP4 中

您可以使用 php.net 中的此代码来获取临时目录:

if ( !function_exists('sys_get_temp_dir')) { 
  function sys_get_temp_dir() { 
    if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); } 
    if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); } 
    if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); } 
    $tempfile=tempnam(__FILE__,''); 
    if (file_exists($tempfile)) { 
      unlink($tempfile); 
      return realpath(dirname($tempfile)); 
    } 
    return null; 
  } 
}
于 2016-08-25T12:46:50.937 回答