Skip to content
Advertisement

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

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement