title: How to upload images to a new unique folder every session php
body: <p>I'm in the process of making a website for my dad that allows people to upload their own personal images because he is a window cleaning tech. He wants to allow people to be able to upload their images so he can give them an estimate on the cost. Below, I have two bits of code. The first bit successfully uploads images. That I won't have to worry about. The second bit, however, does not successfully upload images. What I want to accomplish is that every time a user uploads a set of images (maximum of 5), it will make a new folder in a directory that sets the current time as the name of the folder, that way it will be easier for him to keep track of who sends what. I'm still working out little details on how he can identify a person solely based on images (perhaps a person will call after sending the images in and verify the time of submission?). I am trying to do this with as little use for a database as possible, being I don't know how to use MySQL and tie it to PHP.</p>
  
  <p>This is the code that works and successfully uploads the images to /upload:</p>
  
  <pre><code>&lt;?php
      $uploadpath = 'upload/';
      $max_size = 4000;
      $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png');
      if(isset($_FILES['fileup']) &amp;&amp; strlen($_FILES['fileup']['name']) &gt; 1){
          $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
          $sepext = explode('.', strtolower($_FILES['fileup']['name']));
          $type = end($sepext);
          list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
          $err = '';
          if(!in_array($type, $allowtype)) $err .= 'The file: &lt;b&gt;'. $_FILES['fileup']['name']. '&lt;/b&gt; does not have an allowed extension type.';
          if($_FILES['fileup']['size'] &gt; $max_size*1000) $err .= '&lt;br/&gt;Your file exceeds the '. $max_size. ' KB. size limit.';
          if($err == ''){
              if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)){ 
                  echo 'File: &lt;b&gt;'. basename( $_FILES['fileup']['name']). '&lt;/b&gt; successfully uploaded:';
                  echo '&lt;br/&gt;File type: &lt;b&gt;'. $_FILES['fileup']['type'] .'&lt;/b&gt;';
              }
              else echo '&lt;b&gt;Unable to upload the file.&lt;/b&gt;';
          }
          else echo $err;
      }
  ?&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST" enctype="multipart/form-data"&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      &lt;input type="submit" name='submit' value="Upload" /&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>And here's the code I'm trying to change to make a new folder with the timestamp as the name:</p>
  
  <pre><code>&lt;?php
      $uploadpath = 'upload/';
      $max_size = 4000;
      $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png');
      if(isset($_FILES['fileup']) &amp;&amp; strlen($_FILES['fileup']['name']) &gt; 1){
          $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
          $sepext = explode('.', strtolower($_FILES['fileup']['name']));
          $type = end($sepext);
          list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
          $err = '';
          if(!in_array($type, $allowtype)) $err .= 'The file: &lt;b&gt;'. $_FILES['fileup']['name']. '&lt;/b&gt; does not have an allowed extension type.';
          if($_FILES['fileup']['size'] &gt; $max_size*1000) $err .= '&lt;br/&gt;Your file exceeds the '. $max_size. ' KB. size limit.';
          if($err == ''){
              $uploadpath = "upload/" . time();
              $count = 0;
              foreach ($_FILES['fileup']['name'] as $filename){
                  $temp = $_FILES['fileup']['tmp_name'][$count];
                  move_uploaded_file($temp, $uploadpath . '/' . $filename);
                  $count++;
              }
              if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)){ 
                  echo 'File: &lt;b&gt;'. basename( $_FILES['fileup']['name']). '&lt;/b&gt; successfully uploaded:';
                  echo '&lt;br/&gt;File type: &lt;b&gt;'. $_FILES['fileup']['type'] .'&lt;/b&gt;';
              }
              else echo '&lt;b&gt;Unable to upload the file.&lt;/b&gt;';
          }
          else echo $err;
      }
  ?&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST" enctype="multipart/form-data"&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      Upload File: &lt;input type="file" name="fileup" /&gt;&lt;br/&gt;
      &lt;input type="submit" name='submit' value="Upload" /&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>the main difference between the two is after the <code>if($err == '')</code>, the second bit of code has one more block here to replace the original "move file" command</p>