Home > database >  Do I need to cleanup files created by tempnam() myself?
Do I need to cleanup files created by tempnam() myself?

Time:04-29

I created a bunch of tempnam() files for use during my request. Do I need to specifically unlink() them when they're not needed anymore, or will PHP / the system take care of it themselves?

CodePudding user response:

Files created by tempnam() will not be deleted by PHP.

You'll have to unlink() them manually.


If you need a temporary file thats automatically deleted by PHP, consider using tmpfile():

Creates a temporary file

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.

CodePudding user response:

Yes, unlink (delete) temp files when you're done with them. Some, but not all, OSs clean up their temp directories once in a while. But tempname() uses directories other than the OS temp directories.

  • Related