Removing files programmatically

If you want to remove the images from folder, There is a two way to remove image 1) Remove by manually 2) Remove by using plugin.

1) Using Plugin
I suggest you that can try the Image Cleanup plugin and it’s the best, but still good to make a backup first. There is an another one plugin available to delete un used images DNUI.

DNUI plugin will search image from the database and delete all unused images making space in your server and clean up the database from all them.

2) Manually
You can also search through your Media Library for images which are unattached to posts and pages to delete them manually.

enter image description hereSimply go to Media > Library and click the Unattached link which will display all images that may be displayed on other parts of your site or simply not used.

It’s advisable to take a backup of your uploads folder & database before deleting any images stored in these directories and data in your db.