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

  • Home
  • SEARCH
  • 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 6738005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:18:58+00:00 2026-05-26T11:18:58+00:00

Idea is this: User uploads a file(s) in some temp folder that exist only

  • 0

Idea is this:

  1. User uploads a file(s) in some “temp” folder that exist only for current session.
  2. User registers
  3. Files form “temp” folder are moved to permanent folder aka storage.

I can do something like this:

mkdir('tempfiles/'.session_id(), 777)

And upload files:

if (move_uploaded_file($_FILES['my_files']['tmp_name'], 'tempfiles/'.session_id().'/')) {
  // echo "success";
}

When user register, files are moved to some other folder, temp folder is removed like this:

/* some function to empty dir */
rmdir('tempfiles/'.session_id())

Problem is:
What if user after uploading does not register? How to remove temp folder?

With tempnam function I can create a folder that “will remove it self”..
but in Windows server I can’t create for example tempnam('/tmp/test', '');, just set 3 character prefix: C:\Windows\Temp\pre569E.tmp

My only idea is to write to database path of temp folders.

Any help would be most welcome.

  • 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-26T11:18:58+00:00Added an answer on May 26, 2026 at 11:18 am

    If the user doesn’t register, you’ll have to manually go in and clean up those files. PHP will only auto-clean an upload if you’ve left the original temp file alone. Since you’ve explicitly moved it out of the upload temp directory, that means it’s entirely up to you to clean up.

    You can’t rmdir a non-empty directory. You must remove all the files in that directory first. Simplest method would be to do

    $files = glob('tempfiles/' . session_id());
    foreach($files as $file) {
       unlink($file);
    }
    

    Even easier is to NOT create a subdirectory for each user. Move the file out of the upload temp directory (so PHP won’t auto-clean it) and store it in ANOTHER single intermediate directory with the session_id() as its filename. This limits each unregistered user to a single file held in abbeyance, but that’s probably a good thing. All the users’ files will be intermingled, but since each one has a unique session-based name, there’s no conflict.

    You’d still have to clean up orphaned files from users who opted to not register, but that’d be a simple matter of checking if, for every one of these temporary files, there’s no matching session file – if there’s no session file, then the user’s abandoned the session and PHP has removed the stale session file. So you can have a timed job do this cross-check and remove any of the files which have no matching session.

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

Sidebar

Related Questions

I have no idea why this is happening. I have some very straightforward code,
I have no idea why this doesn't work, but doing some validation functions and
I'm using Uploadify and Kohana and I'm creating file uploader. User can upload only
I have this idea for a free backup application. The largest problem I need
I got this idea a long time ago when i saw an app do
I had this idea of creating a count down timer, like 01:02, on the
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
Any idea why this wont print the errors? // Validate the email if (preg_match($regex,
Any idea why this is popping up :( ? You have an error in
I have no idea if this is possible, but if it is, what would

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.