0

In short, the following code is meant to create a directory structure like:

>Attachments
  >Lot
    >Layer

The Attachments directory is fixed. The Lot comes out with 0777 permissions. The Layer directory does not. I added the chmod lines after concern that perhaps umask was at fault, but it didn't change anything.

// Create directory for this entry's attachments if needed.
  $attachment_dir = $config_ini['OOCDB_defaults']['attachment_dir'];
  $attachment_lot_dir = $attachment_dir.$txtLotID."/";
  $attachment_lot_layer_dir = $attachment_lot_dir . $txtLayer."/";


  if(!is_dir($attachment_lot_dir)){
      mkdir($attachment_lot_dir , 0777);
  }

  if(!is_dir($attachment_lot_layer_dir )){
      mkdir($attachment_lot_layer_dir , 0777);
  }

  chmod($attachment_lot_dir ,0777);
  chmod($attachment_lot_layer ,0777);   
  $sleuthFile = $attachment_lot_layer_dir . "makeSleuthImg.txt";
  $fp = fopen($sleuthFile,"w") or die("unable to open File! <br>");
  //Write the string to the file and close it.
matwr
  • 1,548
  • 1
  • 13
  • 23

1 Answers1

1

You have a typographical error:

$attachment_lot_layer_dir = $attachment_lot_dir . $txtLayer."/";
...
chmod($attachment_lot_layer ,0777);

That variable does not exist, so yes that will never work. PHP's mkdir respects umask in Linux (assuming you're on Linux otherwise this wouldn't be happening), so your directories are not being created at 0777 mask as requested; however chmod does not respect umask, so your first call to chmod is in fact changing this directory's mask to 0777. The second call is failing due to the bad variable name. Hence the behavior you're seeing.

FWIW, mkdir has a second optional, boolean parameter that will allow you to recursively create a directory structure in a single call by passing it the full directory path (see here). You should also look at this question to understand what to do with umask before calling mkdir if you want to avoid the subsequent calls to chmod entirely.

parttimeturtle
  • 1,125
  • 7
  • 22