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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:56:16+00:00 2026-05-25T16:56:16+00:00

I am building a web-app that users can upload certain files and work on

  • 0

I am building a web-app that users can upload certain files and work on them through the web-app interface. I need to store these files for the length of a users session. I am creating a folder for each user using the session_id as the folder name and storing the files in there.

The problem: There is nothing to indicate that a user walked away from my site and the session is going out of use. I need a cleanup script that takes the name of each folder and checks if that session_id is still active in order to delete unused and now unreachable folders. How can I do this?

  • 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-05-25T16:56:18+00:00Added an answer on May 25, 2026 at 4:56 pm

    I have had precisely the same issue. My solution was to check for the session file:

    <?php
    // clean-up script.  Get cron/windows task scheduler to run this every hour or so
    
    // this is the path where PHP saves session files
    $session_path = ini_get('session.save_path');
    
    // this is the directory where you have created your folders that named after the session_id:
    $session_files_dir = '/path/to/your/save/dir';
    
    // loop through all sub-directories in the above folder to get all session ids with saved files:
    
    if ($handle = opendir($session_files_dir)) {
    
        while (false !== ($file = readdir($handle))) {
    
            // ignore the pseudo-entries:
            if ($file != '.' && $file != '..') {
    
                // check whether php has cleaned up the session file
                if (  file_exists("$session_path/sess_$file")  ) {
                    // session is still alive
                } else {
                    // session has expired
                    // do your own garbage collection here
                }
    
            }
        }
    
        closedir($handle);
    }
    
    ?>
    

    Note that this assumes that the session.save_handler ini setting is set to "files", the session.save_path setting does not have the directory-level prefix (i.e. does not match regex /^\d+;/ ) and that php’s automatic session garbage collection is enabled. If either of the above assumptions are not true then you should be implementing manual session garbage collection anyway, so can add your clean-up code to that.

    This also assumes that the only files in $session_files_dir are your per-session folders and they are all named after their associated session_id.

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

Sidebar

Related Questions

I'm building a web app where users can build custom web pages that pull
I am building a web application on Google App Engine that requires users to
I'm building a small web app that allows users to list their goals. I
We're building a web app that customers can pay a monthly rate for. Here
I am currently building a web app that is for Australian based users but
I'm building a web app that needs to work offline. The system is built
I'm building a web-app that handles internal emails and other frequent small-to-medium sized chunks
I'm building a web app that relies quite heavily on email notification/responses. I obviously
I'm building a new web app that has a requirement to generate an internal
I'm looking at building a simple web app that will expose an API that

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.