/** * Create a temp file * * @param string $name A name for the file name * @param string|null $contents Optional contents for the file * @return string The path to the newly created temp file */ public static function file($name = "temp", $contents = null) { $tmpdir = self::getDir(); $name = File::sanitizeName($name); list($name, $ext) = File::splitName($name, ""); if ($ext !== "") { $ext = ".{$ext}"; } do { $rand = substr(md5(microtime(true) . mt_rand()), 10, 10); $path = $tmpdir . DIRECTORY_SEPARATOR . "{$name}-{$rand}{$ext}"; } while (file_exists($path)); touch($path); if ($contents) { file_put_contents($path, $contents); } self::registerPath($path, false); return $path; }