I am trying to determine if a particular file is fully copied into a folder.
Let's say I have a Samba share called /incoming. I want to monitor the folder from a PHP script for new files and more importantly, I need to know when the file is fully copied into that folder.
I've tried fopen using mode r+, but that doesn't seem to work. I'm also looking at the filesize from fstat, but it appears that this info is set at file creation under Samba.
The motivation: I need to process the file in that folder once the file has been fully copied. I am dealing with gigabyte sized files so it can take several minutes for the file to fully copy into the folder. This has to be "user friendly" so easy solutions like creating a ".done" file in the same folder is out of the question. The end users will only see the /incoming folder and drop their files into it.
Any ideas on how I can solve this problem in PHP?
Detecting that a file is done being copied
Moderator: General Moderators
Re: Detecting that a file is done being copied
In your monitoring script, only process files that have a modified time < 1 minute ago. When a file is being uploaded, it should be updated at least every minute - so you can fairly safely assume that when the modified time < 1 minute ago, the upload is finished.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.