Search code examples
phpfunctionmergedelete-fileunlink

Merge two functions that basically do the same thing


I'm currently using two functions to delete from each folder after 1 minute but as they basically do the same thing (just different folders called). I was wondering if they could be merged into one?

function DeleteFromFolder1() {
    $captchaFolder = 'folder1/';
    $fileTypes     = '*.jpg';
    $expire_time   = 1; 
    foreach(glob($captchaFolder . $fileTypes) as $Filename) {
     $FileCreationTime = filectime($Filename);
     $FileAge = time() - $FileCreationTime; 

if($FileAge > ($expire_time * 60))
   {
    unlink($Filename);
          }
       }
    }

function DeleteFromFolder2() {
    $captchaFolder = 'folder2/';
    $fileTypes     = '*.jpg';
    $expire_time   = 1; 
    foreach(glob($captchaFolder . $fileTypes) as $Filename) {
     $FileCreationTime = filectime($Filename);
     $FileAge = time() - $FileCreationTime; 

if($FileAge > ($expire_time * 60))
   {
    to ($Filename);
          }
       }
    }

Solution

  • Thanks for your answers everyone but I have now sorted it by adding:

    unlink(path/to/temp/image.jpg);
    

    to my results page which deletes the uploaded image once the thumb is created and removed the function associated with it.

    Once again thanks for your answers :)