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