php – How to create multiple folders with mkdir

Question:

Hi, I would like to know how to create several folders at once, for example, with this code:

<?php
        $empresa = "Google";
        $tipo = "Abertura";
        $nome = "Contrato Social";

        mkdir('$empresa/$tipo/$nome');
?>

Now with this data I would like to create in this case 3 folders that would be Google -> Opening -> Social Contract, in this case google is the parent folder and opening is inside it, and social contract is another folder that is inside opening, which is inside google, it was a little confused but it would be something like this:

Companies\Google\Opening\Social contract

EDIT:

I set up something more or less like this but it still gives an error, it doesn't create the folders inside, it creates outside like Joaquim Sauro.FGTS

<?php
$nome_user = "Joaquim Sauro";
$tipo = "FGTS";
$categoria = "Abertura";
$pdf = "pdf.pdf";

$pathName = "html/empresas/" . $nome_user;

   mkdir($pathName,0777,true); 
    echo "OK1";

$pathName2 = "html/empresas/.$nome_user."/"" . $tipo;

    mkdir($pathName2,0777,true); 
     echo "OK1.1";

$pathName3 = "html/empresas/.$nome_user."/".$tipo."/"" . $categoria;

    mkdir($pathName3,0777,true);
     echo "OK1.2";

move_uploaded_file($pdf,$pathName3);
?>

Answer:

It could be because of the interleaving of texts with variables, try the code below:

<?php
$nome_user = "Joaquim Sauro";
$tipo = "FGTS";
$categoria = "Abertura";
$pdf = "pdf.pdf";

$pathName = "html/empresas/{$nome_user}/{$tipo}/{$categoria}";
mkdir($pathName, 0777, true);
echo "OK";

move_uploaded_file($pdf, $pathName);

?>

Scroll to Top