title: How to upload a file to a specific folder using httpClient
body: <p>I am trying to upload a zip file to FTP server using Apache HttpClient. </p>
  
  <p><strong>My java code is like this:</strong></p>
  
  <pre><code>public void doFileUpload(String Localfile, String myurl) {
  HttpClientBuilder builder = HttpClientBuilder.create();
  HttpClient httpClient = builder.build();
  
  HttpPost httpPost = new HttpPost(myurl);
  MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
  entityBuilder.addBinaryBody("file", new File(Localfile));
  
  final HttpEntity entity = entityBuilder.build();
  System.out.println(entity.getContentLength());
  
  httpPost.setEntity(entity);
          try {
              HttpResponse response = httpClient.execute(httpPost);
              System.out.println(response.toString());
              System.out.println("Success");
          } catch (IOException  ex) {
              System.out.println("Failed"+ex);
              Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex);
          }
  </code></pre>
  
  <p><strong>In my php File :</strong></p>
  
  <pre><code>if (!empty($_FILES["file"]["name"])) {
          $dat = time();
      $file_name=$_FILES["file"]["name"];
      $temp_name=$_FILES["file"]["tmp_name"];
          $target_path = $file_name."-".$dat;
  
  if (is_uploaded_file($temp_name)) {
    echo "File ". $target_path ." uploaded successfully.\n";
    move_uploaded_file ($temp_name, $target_path);
  } else {
    echo "Possible file upload attack: ";
    echo "filename '". $temp_name . "'.";
    print_r($_FILES);
  }
  }
  </code></pre>
  
  <p>This works fine if I upload a file to the folder where my php file exists. But In my condition, user will upload their files to their own folder. Example: User A will upload a file to <code>myftp/upload/A/</code> or user B will upload a file to <code>myftp/upload/B/</code> The target folder is defined from the user end. I can create folder for all the users manually and place a php file in every folder. But how can I do this with a single php file ?</p>