php:: how long to tmp files stay?

Hailwood picture Hailwood · Jan 11, 2011 · Viewed 39.8k times · Source

I am working on an upload script.

If a user uploads a file and it already exists I want to warn the user (this is all through ajax) and give them the option to replace it, or cancel.

Instead of moving the file, I was curious if I could just leave the file in tmp and pass back the path to that file in the ajax response.

If they user says overwrite the old file in that ajax request pass the path back to php which continues to work on the file.

For this to work however I need to know how long a file stays in php's tmp dir

Answer

zerkms picture zerkms · Jan 11, 2011

Files uploaded through POST are deleted right after php script finishes its execution.

According to php.net: "The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed."