Search code examples
phpvariablesconcatenationmkdir

Creating a directory in PHP based on a bunch of variables


I've been trying to create a directory following a specific structure, yet nothing appears to be happening. I've approached this by defining multiple variables as follows:

 $rid = '/appicons/';
 $sid = '$artistid';
 $ssid = '$appid';
 $s = '/';

and the function I've been using runs thusly:

 $directory = $appid;
 if (!is_dir ($directory)) 
    { 
     mkdir($directory); 
    }

That works. However, I want to have the following structure in created directories: /appicons/$artistid/$appid/

yet nothing really seems to work. I understand that if I were to add more variables to $directory then I'd have to use quotes around them and concatenate them (which gets confusing).

Does anyone have any solutions?


Solution

  • $directory = "/appicons/$artistid/$appid/";
    if (!is_dir ($directory)) 
    {
         //file mode
         $mode = 0777;
         //the third parameter set to true allows the creation of 
         //nested directories specified in the pathname.
         mkdir($directory, $mode, true);
    }