If a directory does not exist, i create the directory and save a file, i can also just save a file if the directory exists. One file should be created at a time not all at the same time as the code below does. If the first file is created now then the next should only be created when the function is called. The files are Named R1,R2….Rn. How can I achieve this, This creates them all at the same time
$fileName1=$fileName1='somedir/'.$thedir.'/'.$thefile.'_R1.xlsx';
...
if (!dir($dirName))
{
mkdir('somedir/' . thedir, 0777);
$objWriter->save($fileName);
}
if (dir($dirName) && (!file_exists($fileName)))
{
$objWriter->save($fileName);
}
if (dir($dirName) && file_exists($fileName))
{
$objWriter->save('somedir/' . $thedir . '/' . $thefile . '_R1.xlsx');
}
if (dir($dirName) && file_exists($fileName1))
{
$objWriter->save('somedir/' . $thedir . '/' . $thefile . '_R2.xlsx');
}
...
You have to add error handling, and note that just checking for a file can create concurrency issues (two processes trying both seeing that the file doesn’t exist and try to create it).