}
/**
- * Tries to get the system directory for temporary files.
- * The TMPDIR, TMP, and TEMP environment variables are checked in sequence,
- * and if none are set /tmp is returned as the generic Unix default.
+ * Tries to get the system directory for temporary files. For PHP >= 5.2.1,
+ * we'll use sys_get_temp_dir(). The TMPDIR, TMP, and TEMP environment
+ * variables are then checked in sequence, and if none are set /tmp is
+ * returned as the generic Unix default.
*
* NOTE: When possible, use the tempfile() function to create temporary
* files to avoid race conditions on file creation, etc.
* @return String
*/
function wfTempDir() {
+ if( function_exists( 'sys_get_temp_dir' ) ) {
+ return sys_get_temp_dir();
+ }
foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
$tmp = getenv( $var );
if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
$this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch.");
}
- $content = tempnam( sys_get_temp_dir(), "" );
- $headers = tempnam( sys_get_temp_dir(), "" );
+ $content = tempnam( wfTempDir(), "" );
+ $headers = tempnam( wfTempDir(), "" );
if ( !$content && !$headers ) {
die( "Couldn't create temp file!" );
}
require_once "$IP/includes/GlobalFunctions.php";
require_once "$IP/includes/Hooks.php";
-// for php versions before 5.2.1
-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;
- $temp=tempnam(__FILE__,'');
- if (file_exists($temp)) {
- unlink($temp);
- return dirname($temp);
- }
- return null;
- }
- }