PHP mkdir get dynamic path

时间:2015-07-28 15:37:20

标签: php

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

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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);

}