title: How can I create folder dynamically when moving image?
body: <p>I use laravel 5.3</p>
  
  <p>My code to move image like this :</p>
  
  <pre><code>private function savePhoto($photos, $id)
  {
      foreach($photos as $key =&gt; $photo) {
          $temp = storage_path() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . $photo['name'];
          $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img'. DIRECTORY_SEPARATOR .'products'.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.$photo['name'];
          if( rename( $temp , $destinationPath )){
              echo 'moved!';
          } 
          else {
              echo 'failed';
          }
      }
  }
  </code></pre>
  
  <p>When executed there exist error like this :</p>
  
  <blockquote>
    <p>rename(C:\xampp\htdocs\myshop\storage\temp\NOTFCjMipXwFhBICo1tj6VXP5Qhv92Fg1kmawcUd.jpeg,C:\xampp\htdocs\myshop\public\img\products\77\NOTFCjMipXwFhBICo1tj6VXP5Qhv92Fg1kmawcUd.jpeg):
    The system cannot find the path specified. (code: 3)</p>
  </blockquote>
  
  <p>I think the error occurred because the $id folder is dynamically generated. The $id folder depends on the parameter id. If parameter id = 77, it will be formed like this:</p>
  
  <blockquote>
    <p>C:\xampp\htdocs\myshop\public\img\products\77\NOTFCjMipXwFhBICo1tj6VXP5Qhv92Fg1kmawcUd.jpeg</p>
  </blockquote>
  
  <p>So the error occurred because folder 77 does not exist yet</p>
  
  <p>How to make folder 77(This is dynamically generated) first before moving the image?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Sample array results from $photos like this :</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 1
              [name] =&gt; vYcHWLXpwhC9WfXd4XCB2emg83WMtWHphyUBq9MV.jpeg
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 2
              [name] =&gt; 1STr51oF8cunSsNEJZyS9upI0hNHYMXjLCCSNonz.jpeg
          )
  
  )
  </code></pre>