function mktemp($args = null)
    {
        static $first_time = true;
        $opts = System::_parseArgs($args, 't:d');
        if (PEAR::isError($opts)) {
            return System::raiseError($opts);
        }

        foreach ($opts[0] as $opt) {
            if ($opt[0] == 'd') {
                $tmp_is_dir = true;
            } elseif ($opt[0] == 't') {
                $tmpdir = $opt[1];
            }
        }

        $prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
        if (!isset($tmpdir)) {
            $tmpdir = System::tmpdir();
        }

        if (!System::mkDir(array('-p', $tmpdir))) {
            return false;
        }

        $tmp = tempnam($tmpdir, $prefix);
        if (isset($tmp_is_dir)) {
            unlink($tmp); // be careful possible race condition here
            if (!mkdir($tmp, 0700)) {
                return System::raiseError("Unable to create temporary directory $tmpdir");
            }
        }

        $GLOBALS['_System_temp_files'][] = $tmp;
        if (isset($tmp_is_dir)) {
            //$GLOBALS['_System_temp_files'][] = dirname($tmp);
        }

        if ($first_time) {
            PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
            $first_time = false;
        }

        return $tmp;
    }
function mktemp($args = null)
    {
        static $first_time = true;
        $opts = System::_parseArgs($args, 't:d');
        if (PEAR::isError($opts)) {
            return System::raiseError($opts);
        }

        foreach ($opts[0] as $opt) {
            if ($opt[0] == 'd') {
                $tmp_is_dir = true;
            } elseif ($opt[0] == 't') {
                $tmpdir = $opt[1];
            }
        }

        $prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
        if (!isset($tmpdir)) {
            $tmpdir = System::tmpdir();
        }

        if (!System::mkDir(array('-p', $tmpdir))) {
            return false;
        }

        $tmp = tempnam($tmpdir, $prefix);
        if (isset($tmp_is_dir)) {
            unlink($tmp); // be careful possible race condition here
            if (!mkdir($tmp, 0700)) {
                return System::raiseError("Unable to create temporary directory $tmpdir");
            }
        }

        $GLOBALS['_System_temp_files'][] = $tmp;
        if (isset($tmp_is_dir)) {
            //$GLOBALS['_System_temp_files'][] = dirname($tmp);
        }

        if ($first_time) {
            PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
            $first_time = false;
        }

        return $tmp;
    }
function mktemp ( $ args = null ) { static $ first_time = true ; $ opts = System :: _parseArgs ( $ args , 't:d' ) ; if ( PEAR :: isError ( $ opts ) ) { return System :: raiseError ( $ opts ) ; } foreach ( $ opts [ 0 ] as $ opt ) { if ( $ opt [ 0 ] == 'd' ) { $ tmp_is_dir = true ; } elseif ( $ opt [ 0 ] == 't' ) { $ tmpdir = $ opt [ 1 ] ; } } $ prefix = ( isset ( $ opts [ 1 ] [ 0 ] ) ) ? $ opts [ 1 ] [ 0 ] : 'tmp' ; if ( ! isset ( $ tmpdir ) ) { $ tmpdir = System :: tmpdir ( ) ; } if ( ! System :: mkDir ( array ( '-p' , $ tmpdir ) ) ) { return false ; } $ tmp = tempnam ( $ tmpdir , $ prefix ) ; if ( isset ( $ tmp_is_dir ) ) { unlink ( $ tmp ) ; // be careful possible race condition here if ( ! mkdir ( $ tmp , 0700 ) ) { return System :: raiseError ( "Unable to create temporary directory $tmpdir" ) ; } } $ GLOBALS [ '_System_temp_files' ] [ ] = $ tmp ; if ( isset ( $ tmp_is_dir ) ) { //$GLOBALS['_System_temp_files'][] = dirname($tmp); } if ( $ first_time ) { PEAR :: registerShutdownFunc ( array ( 'System' , '_removeTmpFiles' ) ) ; $ first_time = false ; } return $ tmp ; }
Creates temporary files or directories. This function will remove
the created files when the scripts finish its execution.

Usage:
1) $tempfile = System::mktemp("prefix");
2) $tempdir  = System::mktemp("-d prefix");
3) $tempfile = System::mktemp();
4) $tempfile = System::mktemp("-t /var/tmp prefix");

prefix -> The string that will be prepended to the temp name
(defaults to "tmp").
-d     -> A temporary dir will be created instead of a file.
-t     -> The target dir where the temporary (file|dir) will be created. If
this param is missing by default the env vars TMP on Windows or
TMPDIR in Unix will be used. If these vars are also missing
c:\windows\temp or /tmp will be used.

@param   string  $args  The arguments
@return  mixed   the full path of the created (file|dir) or false
@see System::tmpdir()
@static
@access  public
Creates temporary files or directories . This function will remove the created files when the scripts finish its execution .