I want to write to a file in the windows temp directory. I know that in the command line you can use the environment variable %TEMP% to get the right path, however trying to do something like this:
file_put_contents("%TEMP%\\myfile.txt");
…does not work because the environment variable isn’t being resolved. Is there a way to do this?
getenv('TEMP')or$_ENV['temp']Incidentally, if you’re working with temporary files, then you might want to look into the
tempnam()andtmpfile()functions.The former will reserve a temporary file name in any directory (although you can have it create a file in the system temporary directory); the latter will actually create a temporary file and return a file handle resource, automatically discarding the temporary file when the handle is closed.