Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    219
    Thanks
    25
    Thanked 1 Time in 1 Post

    delete all files in folder error

    this script deletes files older then 10 minutes. It works but if the directory is empty it throws out this error message:

    in file /mdwgold/index.php on line 52: Invalid argument supplied for foreach()

    PHP Code:
    $captchaFolder  '../mdwgold/uploads/';
    $fileTypes      '*.*';
    $expire_time    10
    foreach (
    glob($captchaFolder $fileTypes) as $Filename) {
        
    $FileCreationTime filectime($Filename);
        
    $FileAge time() - $FileCreationTime
         if (
    $FileAge > ($expire_time 60)){
           print 
    "The file $Filename is older than $expire_time minutes\n";
            
    unlink($Filename);
        }
     

    How can I alter the coding so no error will come up?

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    Use glob before the loop and see if there is anything to be deleted before starting the loop. If nothing is returned by glob do nothing otherwise use your loop.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •