If you hold a handle to the file you do not need to bother that. Filesystem is taking care of that.
EDIT
Handle is valid unless you close it or script ends and deleting file is absolutely irrelevant to the validity of the handle and so is locking. One can easily check that by creating i.e. big file (1GB) and start i.e. fetching using browser and you can now "safely" delete it from other process. And this will NOT affect fetching even tools like ls
will no longer list the file as existing. I wrote "safely" because if download fail, then httpd will close opened handle and then, if no other process hold a handle, it will phisicaly free diskspace. But it DOES as long as there's at least one reference to it, data remains on the disk (it can be easily checked by checking free disk space using tools like df
- in sequence:
create 1GB file
df
start download
rm file
df
second df
will indicate that discspace is the same as with 1st one (assuming no other file manipulation occured of course). Now stop downloading and do df
again. Free space is now 1GB in plus.
Please note that Windows' FS won't let you delete opened file, but that's just a matter of implementation not technical limitations. Most (if not each) FS on *nix will handle this without any problem.