title: PHP File Upload using url parameters
body: <p>Is there a way to upload a file to server using php and the filename in a parameter (instead using a submit form), something like this:</p>
  
  <blockquote>
    <p><strong>myserver/upload.php?file=c:\example.txt</strong></p>
  </blockquote>
  
  <p>Im using a local server, so i dont have problems with filesize limit or upload function, and i have a code to upload file using a form</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"&gt;
  &lt;html&gt;
  &lt;body&gt;
    &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" name="fileForm" enctype="multipart/form-data"&gt;
      File to upload:
      &lt;table&gt;
        &lt;tr&gt;&lt;td&gt;&lt;input name="upfile" type="file"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;&lt;input type="submit" name="submitBtn" value="Upload"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;  
    &lt;/form&gt;
  &lt;?php    
  if (isset($_POST['submitBtn'])){
  
      // Define the upload location
      $target_path = "c:\\";
  
      // Create the file name with path
      $target_path = $target_path . basename( $_FILES['upfile']['name']); 
  
      // Try to move the file from the temporay directory to the defined.
      if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
          echo "The file ".  basename( $_FILES['upfile']['name']). 
               " has been uploaded";
      } else{
          echo "There was an error uploading the file, please try again!";
      }
  }
  ?&gt;
  &lt;/body&gt;  
  </code></pre>
  
  <p>Thanks for the help</p>