title: PHP create folder if it does not exist
body: <p>I am creating a medium size application.</p>
  
  <p>This application consists of a lot of products.</p>
  
  <p>Now these products have many images (one product can have 5 - 6 images)</p>
  
  <p>To try and make some sort of ordering I want to create one folder for each product this folder contains all images that is bound to the product.</p>
  
  <p>Now so far I have tried the following:</p>
  
  <pre><code>move_uploaded_file($file, APP.'product_images/'.$product_id.'/'.$image['name']);
  </code></pre>
  
  <p>However when I try this I get the following error:</p>
  
  <pre><code>Warning (2): move_uploaded_file(/var/www/udlejnings-priser/cake/app/product_images/22/afterClick.png): failed to open stream: No such file or directory [APP/Controller/ImagesController.php, line 56]
  
  Warning (2): move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php472ci6' to '/var/www/udlejnings-priser/cake/app/product_images/22/afterClick.png' [APP/Controller/ImagesController.php, line 56]
  </code></pre>
  
  <p>Now I am not a complete noob and know that this means that I am missing permissions to the folder.</p>
  
  <p>However the problem is that if the folder does not exist (i.e this is the first time an image for that product is uploaded) then a new folder should be created.</p>
  
  <p>My question is two parted.</p>
  
  <ol>
  <li>Does this automatically create a new folder if it doesn't already exist?</li>
  <li>How can I give permission to a newly created folder so that I avoid this problem?</li>
  </ol>