1
I have been trying to do a function that could delete files from within a given directory according to an informed date. In this example below I have not yet created the function because I am still trying to understand how to do.
echo "<br />";
$arquivo = 'documento.pdf';
if(date("November 05 2016 19:19:24.", fileatime($arquivo))){
echo "Excluiu!";
unlink($arquivo);
} else {
echo "Não excluiu!";
}
A very basic example of what I’m trying to do is delete files from a folder that are more than 3 months old. I can’t understand how I can spend this time and use it as a parameter in a function (because I can change the time if I need to)
Linux or Windows server?
– Pedro Sanção
windows server
– Diego Souza
3 months since creation?
– rray
This. An upload will be made to a particular folder. This script would only check from the date of the upload of that file to the folder. If you had more than 3 months in the folder, it would delete the file, otherwise it would do nothing.
– Diego Souza
If at the time of upload you can save the date of when it was made, it is more reliable that
fileatime()
. To run this periodically you can use the cronjob or windows task scheduler– rray
I’ve heard of cronjob, but I’ve never used it yet. I’ll try to learn how to use it.
– Diego Souza