0

I want to create a folder on my server named after the current date. My variable would be: $foldername = date('HisYmd');

I have two scripts that both upload one file to the folder, one of the scripts creates the folder when the submit button is pressed, the other script uploads bigger files so it's like 5 seconds slower.

So basically my question is, how can I lock $foldername for the two scripts so that it doesn't change every second?

1 Answer 1

2

Use session variables.

Example:

in file 1:

if(!session_id())
 session_start();
$_SESSION['foldername'] = $foldername  = date('HisYmd');

in file 2:

if(!session_id())
 session_start();
if(isset($_SESSION['foldername']) && !empty($_SESSION['foldername']))
  $foldername = $_SESSION['foldername'];
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. I've tried it and it still creates two different folders for me, with a few seconds difference between them. gyazo.com/76e3cd06976bbbaf72e8311533e72079
Oh I switched the code between files (file 1 to file 2 and vice versa) and it worked now :) Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.