Detecting that a file is done being copied

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rongage
Forum Newbie
Posts: 1
Joined: Tue May 12, 2009 7:34 am

Detecting that a file is done being copied

Post by rongage »

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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Detecting that a file is done being copied

Post by pickle »

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.
Post Reply