John_A Posted September 18, 2013 Share Posted September 18, 2013 I've got a thumbnailing script I'm using which uses phpThumb(), but as an object which means I'm having to handle my own cache. What I've got in a folder is: - [phpthumb].htaccess index.php When used, the script will create additional files / folders in here, which are cached versions of images pulled from elsewhere, so for example I might end up with: - [holidaysnaps] [phpthumb] [work-images] .htaccess dsc123467.jpg index.php lolcat.gif etc. etc. My script is at index.php and I want to add a CleanUpCacheDirectory() function to it so that it manages the cache as well. I've tried taking phpThumb's CleanUpCacheDirectory() function and modifying to suit but the first major problem is that it requires a folder to point at and deals with everything inside that, which I can't do here as that would include the phpthumb folder itself, as well as my index.php script and the .htaccess file. And for various reasons, I really don't want to add a "cache" folder in here. Ideally I'd like the same options as phpThumb, i.e.: - //$PHPTHUMB_CONFIG['cache_maxage'] = null; // never delete cached thumbnails based on last-access time $PHPTHUMB_CONFIG['cache_maxage'] = 86400 * 30; // delete cached thumbnails that haven't been accessed in more than [30 days] (value is maximum time since last access in seconds to avoid deletion) //$PHPTHUMB_CONFIG['cache_maxsize'] = null; // never delete cached thumbnails based on byte size of cache directory $PHPTHUMB_CONFIG['cache_maxsize'] = 10 * 1024 * 1024; // delete least-recently-accessed cached thumbnails when more than [10MB] of cached files are present (value is maximum bytesize of all cached files) //$PHPTHUMB_CONFIG['cache_maxfiles'] = null; // never delete cached thumbnails based on number of cached files $PHPTHUMB_CONFIG['cache_maxfiles'] = 200; // delete least-recently-accessed cached thumbnails when more than [200] cached files are present (value is maximum number of cached files to keep) With these set, I'd want to loop through all folders / files in the current folder, but excluding the phpthumb folder (and everything in it), and also ignoring the .htaccess and index.php files. If it helps, the phpThumb CleanUpCacheDirectory() function is about 1/5th of the way down here: http://phpthumb.sourceforge.net/index.php?source=phpthumb.class.php Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/282249-delete-files-folders-in-current-with-exclusions/ Share on other sites More sharing options...
AbraCadaver Posted September 18, 2013 Share Posted September 18, 2013 The best thing to do would be to create a tmp dir or something and point phpthumb to that dir and let it manage stuff. Quote Link to comment https://forums.phpfreaks.com/topic/282249-delete-files-folders-in-current-with-exclusions/#findComment-1450071 Share on other sites More sharing options...
John_A Posted September 20, 2013 Author Share Posted September 20, 2013 I did want to avoid that but I guess adding that in was easier than trying to rewrite the CleanUpCacheDirectory() function.... Needed a little tweaking but I managed to get it working...I think! Quote Link to comment https://forums.phpfreaks.com/topic/282249-delete-files-folders-in-current-with-exclusions/#findComment-1450427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.