title: How to set my target folder for an upload with a variable, in php?
body: <p>I am new to php, hence cannot figure out my problem.
  I have an HTML form that is connected to the mentioned php file. This form works fine. The problem is with the php file.
  The HTML form is:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;body&gt;
  
      &lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
      Select image to upload:
      &lt;input type="file" name="fileToUpload" id="fileToUpload"&gt;
      &lt;input type="submit" value="Upload Image" name="submit"&gt;
      &lt;/form&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>And my php file called upload.php is:</p>
  
  <pre><code>    &lt;?php
      $uid = $_POST['uid'];
      $target_dir = "FILES OF:$uid";
      $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
      $uploadOk = 1;
      $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
      // Check if image file is a actual image or fake image
      if(isset($_POST["submit"])) {
      $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
      if($check !== false) {
      echo "File is an image - " . $check["mime"] . ".";
      $uploadOk = 1;
      } else {
      echo "File is not an image.";
      $uploadOk = 0;
      }
      }
      ?&gt;
  </code></pre>
  
  <p>Here, as you can see in the first lines of the php code, the target directory is set. But I want it to be with a variable called</p>
  
  <pre><code>    $uid
  </code></pre>
  
  <p>which is linked to the uid field in my database meaning username. What I mean to say is that I want it to upload files in the folder called "FILES OF:$uid".
  I have these folders already created but want a way in which files will go directly to that folder. 
  Does anyone know a way to do this?</p>