check if file is in use with php

2

I have a file called photo.zip, where people can download it to my site. I want to create a file in php that crontab will run every 10 minutes, and check if the file is being downloaded by someone. If it is not, it deletes the file.

Someone knows how to do this.

    
asked by anonymous 17.06.2016 / 15:04

1 answer

2

First, we must know what your server is.

If it's apache, you should go to this documentation section (access logs) and check which access file.

If it's IIS, visit this documentation section and see where the log files are. From what you posted I think not this one.

In both cases, you have to check that the version of your server is in accordance with the documentation I suggested.

The second step is to make these logs accessible to the query via php. For security reasons, I recommend that your crontab php script, take a copy of this file to another directory and do the verification.

Another alternative, and I think this is more recommended. It is you create in the access page a button that will take action to manage the file download. I believe there should be a php / javaScript / Ajax treatment so that while the download is in progress, it generates a flag (eg a .lock- [date] - [time] file) that is erased after the download is finished or stopped. When your crontab program runs and does not find any flag, then it deletes the file.

    
17.06.2016 / 15:22