How to clear cache folder of opencart website

2.4k Views Asked by At

Have a live old website containing 20 GB of images files (in cache folder) built on opencart. Many products were deleted in recent years from the database but its images left in the cache folder. This is piled up to more than 12 GB in that 20 GB total.

I need to clean this folder and keep all images files that are from live products and the rest I want to delete. Not possible to achieve this manually.

I am thinking to create a script in PHP, that will read the first 10 files in that and match their name from the database and if the files name does not exist in the database, then delete that file. And then set this script in a CRON job to run every 5 min. help me to create such a script or a better idea to achieve this? This needs to perform on a live server.

Glitches: scandir or any other function scans the entire directory. Is there any way to scan only first (n) files and clean these.

Open cart created many versions of a single image file depending on its dimensions. i.e xy.jpg, xy-50x50.jpg , xy-100x100.jpg etc.

1

There are 1 best solutions below

2
On

In OpenCart engine, images will be created again in the /image/cache/ folder from originals from /images/catalog/. The cache folder is for temporary files, so you can remove content form it.