tmpfile()
creates a temporary file with a unique name in read-write (w+) mode and returns a file handle to use with fwrite for example.
$temp = tmpfile();
fwrite($temp, file_get_contents("$path/$filename"));
The file is automatically removed when closed (for example, by calling fclose(), or when there are no remaining references to the file handle returned by tmpfile()), or when the script ends. look at php ref.