18.3. Creating a Temporary File18.3.2. SolutionUse tmpfile( ) if the file needs to last only the duration of the running script:
If the file needs to last longer, generate a filename with tempnam( ), and then use fopen( ):
18.3.3. DiscussionThe function tmpfile( ) creates a file with a unique name and returns a file handle. The file is removed when fclose( ) is called on that file handle, or the script ends. Alternatively, tempnam( ) generates a filename. It takes two arguments: the first is a directory, and the second is a prefix for the filename. If the directory doesn't exist or isn't writeable, tempnam( ) uses the system temporary directory — the TMPDIR environment variable in Unix or the TMP environment variable in Windows. For example:
Because of the way PHP generates temporary filenames, the filename tempnam( ) returns is actually created but left empty, even if your script never explicitly opens the file. This ensures another program won't create a file with the same name between the time that you call tempnam( ) and the time you call fopen( ) with the filename. 18.3.4. See AlsoDocumentation on tmpfile( ) at http://www.php.net/tmpfile and on tempnam( ) at http://www.php.net/tempnam.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|