1

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
ujjawal
  • 95
  • 1
  • 11
  • check this here is your answer https://stackoverflow.com/questions/28539757/how-to-clear-cache-in-opencart-from-php – Full Stop Sep 23 '20 at 04:03
  • Does this answer your question? [How to clear cache in Opencart from PHP](https://stackoverflow.com/questions/28539757/how-to-clear-cache-in-opencart-from-php) – AmirAli Esteki Sep 23 '20 at 04:10
  • No, this solution does not work for me. if i delete content from cache folder, the images disappeared on the website. – ujjawal Sep 23 '20 at 05:49

1 Answers1

2

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.

kanenas
  • 869
  • 1
  • 20
  • 37
focus.style
  • 6,612
  • 4
  • 26
  • 38
  • when i delete images from cache folder, the same are not regenerating and shows missing on the website. – ujjawal Sep 24 '20 at 11:01
  • 2 reasons could be possible: 1. not enough disc space (of all inodes are full), 2. wrong folder/file permissions. On all folders should be 755 and files 644. – focus.style Sep 24 '20 at 12:27