1

I am using mkdir like so

mkdir('somePath\\' . $this->name. '-' . $this->generateRandomString(), 0777, true);

The output can be something like

C:\xampp\htdocs\someFolder\templates\generated\Nick-ycolYWzdin

So, I append a name and random string as the folder name. Problem is, I now need to use PHP to put a file in this folder.

Is there any way to get the path of the folder I just created, including the folder name (with the name and generated string)?

Thanks

4
  • 4
    Seriously? Just save it in a variable... Commented Jul 28, 2015 at 15:39
  • ^ and store it in $_SESSION if you need to use it in another place/time. Commented Jul 28, 2015 at 15:40
  • 1
    Just because it's an easy question doesn't make it a bad question. Don't discourage, please. Commented Jul 28, 2015 at 15:57
  • In all fairness, it was slightly silly now I look at it - been doing too much coding today Commented Jul 28, 2015 at 16:03

2 Answers 2

2

store the mkdir parameter in a variable prior to calling the mkdir function.

$path = 'somePath\\' . $this->name. '-' . $this->generateRandomString();
mkdir($path, 0777, true);
/*
Other stuff happens
*/
move_uploaded_file($file, $path);
Sign up to request clarification or add additional context in comments.

Comments

2

You should store the path in a variableand pass it to mkdir function

$new_path = ''somePath\\' . $this->name. '-' . $this->generateRandomString()';
if (mkdir($new_path)) {
     copy($file, $new_path."/".$file);

}

Comments

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.