dadamssg Posted July 20, 2009 Share Posted July 20, 2009 I'm looking into to creating an image upload option for events, similar to facebook. I run a cron to delete expired events, but i have no idea how i would write code to delete images that are stored in a directory and not just text and numbers in my database. How is this done? Link to comment https://forums.phpfreaks.com/topic/166571-delete-images-stored-in-a-directory/ Share on other sites More sharing options...
Amtran Posted July 20, 2009 Share Posted July 20, 2009 Store the date in the filename, like so: "mysuperawesomeuploadedfile_7-19-09.gif" Aaaand thennn, <?php $handle = opendir('/path/to/file'); while (false !== ($filename = readdir($handle))) { $splitFileName = explode('_', $filename); if (end($splitFileName) < date(n-j-y)) { unlink($filename); } } ?> Link to comment https://forums.phpfreaks.com/topic/166571-delete-images-stored-in-a-directory/#findComment-878433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.