1
The Problem:
I wonder if there is a more practical way than using the control structures IF/ELSE
for creation of folders recursively, based on the inputs that the user typed.
Context:
For example, in my script, I receive the data, validate and sanitize the later ones, and then I create folders with the data of the fields informed, so far so good, but the problem is that some fields are not required to be typed, so if I have, for example 4 fields:
Name, Enterprise, City, State
I wonder if there’s any other way than IF/ELSE
:
$dir = "uploads/{$nome}/{$empresa}/{$cidade}/{$estado}/";
if(!is_dir($dir)):
mkdir($dir, 0777, true);
endif;
To create the folders with the data that was typed, ignoring the empty fields to avoid errors
And what should happen if there is some empty field?
– Woss
It should ignore the $dir variable field if the name field is empty:
$dir="uploads/{$empresa}/{$cidade}/{$estado}/";
and so on until all fields are checked– UzumakiArtanis