title: PHP mkdir Permission Denied running on Windows Server 2008 IIS 7 due to Read Only Attribute?
body: <p>I'm having a problem with a PHP website running on IIS 7 on Windows Server 2008.</p>
  
  <p>There is one line of code calling mkdir which is erroring and the error log reads:</p>
  
  <p>"... permission denied ..."</p>
  
  <p><strong>I have ruled out anything to do with folder permissions (I have tried multiple groups: Everyone, Users, IUSR, Network Service etc. with no luck).</strong></p>
  
  <p><strong>I need to know how mkdir works, does it check the read-only attribute of the parent folder?</strong></p>
  
  <p>If so, then this could be the root of the problem as all folders in Windows Server 2008 are marked as "Read Only" and the checkbox is greyed-out - Microsoft say it is "by design" but I think it is really "bad design".</p>
  
  <p>Please help.</p>
  
  <p>P.S. The line of code which errors can be found here <a href="https://github.com/LimeSurvey/LimeSurvey/blob/070d255ba381d7abcd231d7c9e0c7d11f5578c97/admin/templates.php#L1182" rel="noreferrer">https://github.com/LimeSurvey/LimeSurvey/blob/070d255ba381d7abcd231d7c9e0c7d11f5578c97/admin/templates.php#L1182</a> it is line 1182.</p>
  
  <p>SOLUTION:</p>
  
  <ul>
  <li>It was a permissions issue after all!</li>
  <li>We were applying permissions to the wrong folder (smacks hand to forehead)</li>
  <li>There are two "Templates" folders: /Templates and /Uploads/Templates</li>
  <li>/Template is for default templates whereas /Uploads/Templates is for user-created ones</li>
  <li>We gave the "Users" group r/w/execute/modify permissions to /Uploads/Templates folder</li>
  <li>Whereas previously we were applying permissions to /Templates</li>
  <li>To debug this I used <code>echo</code> to output the <code>$target</code> value</li>
  </ul>
  
  <p>LESSONS LEARNT:</p>
  
  <ul>
  <li>Always read the error message - it said "permission denied" and I didn't believe it</li>
  <li>Don't assume the obvious to be true - /Templates wasn't the right folder</li>
  <li>If the code is erroring then debug the code and don't try to guess the problem</li>
  <li>Debug the code using simple techniques such as outputting variable values - e.g. echo</li>
  <li>Listen to the majority - most people here were right in saying IT IS A PERMISSIONS ISSUE!</li>
  <li>Most errors have a simple fix - don't go looking for something complex</li>
  </ul>
  
  <p>Bounty awarded to @BOMEz because of the useful quote from <code>mkdir()</code> documentation which indicated that I should double-think the permissions. @BOMEz also provided a tailored answer and interacted with me via comments which helped.</p>