title: Auto increment file names PHP/MySQL
body: <p>I am fairly new to the php world and have been creating an inventory tracking system for one of my side businesses. Most of the basics are working, but I am having issues with my "upload pdf" function. Even though it works and uploads the pdf file to its target location, I cannot get the file name ($docid) to be an integer that auto increments every time there is a submission so that files never have the same name. Below is the code I have working:</p>
  
  <pre><code>$pdfPath = "/Documents/TEST/";
  
  $maxSize = 102400000000;
  
  $docid = TEST;
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST' &amp;&amp; isset($_POST['upload_pdf'])) { 
          if (is_uploaded_file($_FILES['filepdf']['tmp_name'])) {
              if ($_FILES['filepdf']['type'] != "application/pdf") {
                  echo '&lt;p&gt;The file is not in PDF&lt;/p&gt;';
              } else if ($_FILES['filepdf']['size'] &gt; $maxSize) {
                  echo '&lt;p class="error"&gt;File is too big! Max size is =' . $maxSize . 'KB&lt;/p&gt;';
              } else {
                  $menuName = "Order_Receipt_".$docid.".pdf";
                  $result = move_uploaded_file($_FILES['filepdf']['tmp_name'], $pdfPath . $menuName);
                  if ($result == 1) {                 
                      echo '&lt;META HTTP-EQUIV=Refresh CONTENT="0; URL=http://localhost/website/enter_new_order_success.html"&gt;';
  
                  } else {
                      echo '&lt;p class="error"&gt;Error&lt;/p&gt;';
                  }
              }
          }
  </code></pre>
  
  <p>I know I need some sort of loop to auto increment that $docid variable but I cannot seem to figure it out. I have read up on the topic, but auto increment with the if statement is throwing me off. Any help would be greatly appreciated.</p>
  
  <p>Cheers</p>