Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:42:40+00:00 2026-06-05T08:42:40+00:00

i think this question was asked few times, which I have went through and

  • 0

i think this question was asked few times, which I have went through and was using some of the code from the net. Right now Im encountering problem with the time.

Let me furnish the code first:

<?php
   $pathToDir = getcwd();               

   $pathToFilesDir = $pathToDir . '\files';

   $pathToFiles = $pathToFilesDir . '\\';

    if ($handle = opendir($pathToFilesDir)) {

        while (false !== ($file = readdir($handle))) { 

            $filelastmodified = filemtime($file);

            if ($file != '.' && $file != '..'){               

                if((time() - $filelastmodified) > 60 && is_file($file)){

                    unlink($pathToFiles . $file);

                }                
            }                 
        }
        closedir($handle); 
    }

?>

This was what I was trying, to auto delete the files which are one minute older. Just for testing purposes I was trying for one minute. The result is that the files dont get deleted. On the other hand I just removed this timing condition

if((time() - $filelastmodified) > 60 && is_file($file))

and ran the script, which could delete the files immediately.

Can any one spot the mistake which I am making?

Thanks
Raaks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:42:43+00:00Added an answer on June 5, 2026 at 8:42 am

    Here my code check cache by lifetime, it works fine.

    if (is_file($dir.$file) && is_readable($dir)) {
        if ($lifetime) {
            @clearstatcache();
            if ((time() - @filemtime($dir.$file)) < $lifetime) {
                return file_get_contents($dir.$file); # Return the cache
            } else {
                @unlink($dir.$file); # Cache has expired
            }
        } else {
            return file_get_contents($dir.$file); # Return the cache
        }
    } return null; # Cache not found
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this question asked a few times but I have not seen
I have seen this question asked here a few times, but most question didn't
I think this question has been asked many a times but I've been searching
This question has been asked on here a few times, but none of the
I asked from few weeks ago this question: How can I teach a beginner
This question has been asked a few times on SO but I couldn't get
I know this question has been asked few times over SO but none of
I've asked this question of a few colleagues who I believe have good design
There have been a few variations of this question asked in the past few
I don't think this question has been asked before. I'm a bit confused on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.