Aside from renaming or moving it when the upload is finished to specify such, your best option is to keep an eye on the file (programmatically). Either watch the modified time or the file size. When it hasn't changed in a minute or so, the file is probably done. Something like this...
my %files = ('foo.txt' => [0,time()], 'bar.csv' => [0,time()]);
while(%files) {
for(keys %files) {
if((-s $_ == $files{$_}[0]) &&
(time()-$files{$_}[1]>60)) {
&move_file($_);
delete $files{$_};
} else {
$files{$_} = [(-s $_),time()];
}
sleep 1;
}
}
this is not tested, and could be optimized, but what it does is have a hash of files (which you could add to as you go along). The values of the hash is an array holding file size and time it last changed. The code checks to see if the size has changed, and if the time it hasn't changed is over 60 seconds... You have to leave some amount of time since data tends to be written in chunks.
If windows changes the modified time as the file gets written a simple
if(time() - (stat $file)[9] > 60)
would be a sufficient test to see if $file has changed in the last 60 seconds...
- Ant
- Some of my
best work - (1 2 3)