Recorded files lock


I am uploading with PHP the files that have been recorded through asterisk with Record() application.

The problem is that while asterisk is recording, the file has already been created.
And I don’t want my PHP script to upload the file while it’s still in process of being recorded by Asterisk.

How can I handle that?
Thank you!

Have the dialplan rename it at the end of the call.