Cron delete files but keep the last

Installed a D-link web camera and realized that it keeps uploading images with an added sequence to it to the ftp server. The camera uploads one image per minute to the folder /webcam1 on a ftp server. To present the current image at a web page I need to:

  1. remove all uploaded files in the folder /webcam1 except the last uploaded.
  2. rename this last file to winther.jpg

How would I do this as a cron job at the web provider?
I’m a noob at PHP, sorry.

You would need at last a few filesystem functions:

https://www.php.net/manual/en/function.glob.php

https://www.php.net/manual/en/function.sort.php

https://www.php.net/manual/en/function.unlink.php

and you can utilize arrays here very efficient

https://www.php.net/manual/en/function.array-pop.php

Sponsor our Newsletter | Privacy Policy | Terms of Service