I've created a file via
$my_dir = '/var/example'
$file_path = tempnam( $my_dir, '' );
Then I tried to convert temp file ($file_path
) to dir.
There is no function tempdir
.
How can I create dir with unique file name inside $my_dir
?
Even, if $my_dir
contains a lot of sub dirs.
Dir name needs to be unique and not necessarily to be random.
Suggested question and answer - is not an answer for my question.
Suggested answer possible could conflict if there is subdir with generated name by uniqid
function.
I need to guarantee - there are no conflicts with existing subdir inside $mydir
.
I need to solve the problem similarly how tempname
works. Analogically, but for directories.
Acording to @RiggsFolly I've found this solution
$file_path = tempnam( $books_dir, '' );
unlink($file_path);
mkdir($file_path);
But theoretically there could be conflict and mkdir then could return false
,
If I start this script multiple times in parallel mode.
Good solution, but not ideal.