title: PHP Single button file upload through internal php function
body: <p>As part of a class I've been asked to create a simple file upload system that uploads files in a single button to a folder called ./files. I've been able to do this and I have been able to keep it all contained in one a3.php file with this:</p>
  
  <pre><code>&lt;form action="a3.php" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="fileToUpload" id="fileToUpload"&gt;
      &lt;input type="submit" value="Upload" name="submitFile"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Which opens up a file dialog and only requires the user to press two buttons</p>
  
  <p>I use the following function to run the upload function.</p>
  
  <pre><code>if(isset($_POST['submitFile']))
  {
      uploadFile();
  }
  </code></pre>
  
  <p>The uploadFile() function simply uses move_uploaded_file to move to file to the ./files folder. Currently without any questions asked.</p>
  
  <p>My issue is that my attempts to make the buttons for the file upload a single one have been stymied. I have attempted to use the following code to resolve the issue:</p>
  
  <pre><code>&lt;form name="frm" action="a3 - Copy.php" method="post" enctype="multipart/form-data"&gt; 
      &lt;input type="file" name="uploadFile" onchange="frm.submit();"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Which, while it refreshes the page as if an action is being performed, appears to do nothing. I have attempted to look into how exactly .submit() works but haven't gotten any closer to understanding any intricacies it may have while a part of onchange.</p>
  
  <p>I've looked around and I've found code that can upload in a single button, and I've found code that can upload using an internal php function, but none that does both.</p>