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 8821387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:50:28+00:00 2026-06-14T05:50:28+00:00

Possible Duplicate: Automatically delete files from webserver I’m logging some XML content to a

  • 0

Possible Duplicate:
Automatically delete files from webserver

I’m logging some XML content to a text file using file_put_contents() in case I need it for debugging.

How do I delete this file after a certain amount of time?

I’ve got a restrictive .htaccess in the log folder, but I’d rather not leave the info (will have customer’s addresses, etc) up on the web for long.

  • 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-14T05:50:29+00:00Added an answer on June 14, 2026 at 5:50 am

    Well, while agreeing with everyone else that you’re using the wrong tool for the job, your question is pretty straightforward. So here you go:

    • write a PHP script that will run from the command line
    • use a tool like cron or windows scheduled task
    • invoke the cron every minute/five minutes/etc

    Your script would be pretty straightforward:

    <?php
       $dh = opendir(PATH_TO_DIRECTORY);
       while( ($file = readdir($dh)) !== false ) {
          if( !preg_match('/^[.]/', $file) ) {  // do some sort of filtering on files
             $path = PATH_TO_DIRECTORY . DIRECTORY_SEPARATOR . $file;
             if( filemtime($path) < strtotime('-1 hour') ) {  // check how long it's been around
                unlink($path);  // remove it
             }
          }
       }
    

    You could also use find if you’re working in Linux, but I see that @Rawkode posted that while I was writing this so I’ll leave you with his elegant answer for that solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to delete a file? My application first reads the fields in
Possible Duplicate: Open a file in the proper encoding automatically my code: import csv
Possible Duplicate: Automatically Deploy From GitHub To Server On Push is there a way
Possible Duplicate: How do I stop visual studio from automatically inserting asterisk during a
Possible Duplicate: Do most browsers automatically search for the favicon.ico? Will a favicon.ico that
Possible Duplicate: ToggleButton state change programmatically rather than automatically in Android? I am trying
Possible Duplicate: Is there a way to automatically update application on Android? As a
Possible Duplicate: Is there a way to automatically update application on Android? I have
Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?
Possible Duplicate: Objective-C: With ARC, what's better? alloc or autorelease initializers? Does ARC automatically

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.