function tempdir($dir, $prefix) { $tempfile = tempnam($dir, $prefix); if (file_exists($tempfile)) { unlink($tempfile); } mkdir($tempfile); return $tempfile; }