i want to create a php script who erase all the photo in one folder but not the last five of them, i dont know if in php is possible to know the date of creation of a file, i really dont know how to do this, thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get the last modified time of a file using filemtime. You mentioned the creation date; On a Windows system you can get the creation time using filectime however on a Unix based system this will just get the changed time since Unix systems don’t store the creation date of a file.
Once you have this info, a basic technique would be to just loop over each file in the folder grabbing their modification times, then delete all but the ones with the 5 latest times.
A quick example, although there’s probably a much more succinct way of doing this,