title: Change file name when sending file from android to server
body: <p>I am writing an application with which a file can be uploaded to a server. During the running of the application, information is written to the file and deleted. Whenever the file is uploaded to the server, I want a new file name so that the old file is not replaced. However, the file can be large and hence I want to maintain only one file on the android system. I want the file name on the server to be having the date and time for when it was uploaded. Is there someway to make the file name on the server to be different from what it is on the device sending it? </p>
  
  <p>I am uploading the file to the server using standard multipart entity framework and php code on the server. The php code is shown below:</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="upload.php" method="POST"&gt;
  &lt;input type="hidden" name="MAX_FILE_SIZE" value="100000" /&gt;
  Choose a file to upload: &lt;input name="uploadedfile" type="file" /&gt;&lt;br /
  
  &lt;input type="submit" value="Upload File" /&gt;
  &lt;/form&gt;
  
  &lt;?php
    $to_file = "locationdata/" . basename($_FILES['uploadedfile']['name']);
    $from_file = $_FILES['uploadedfile']['tmp_name'];
  
    if (move_uploaded_file($from_file, $to_file)) {
      echo "Successful upload";
  ?&gt;
    &lt;a href="&lt;?php echo $to_file;?&gt;"&gt;&lt;?php echo $to_file;?&gt;&lt;/a&gt;
  &lt;?php
    } else {
      echo "Unsuccessful upload";
    }
  ?&gt; 
  </code></pre>
  
  <p>Below are snippets of my code for the android application.</p>
  
  <pre><code>public static File file = new File("/sdcard/upload.txt");
  public static FileWriter writer;
  </code></pre>
  
  <p>This code is in a method I call during the running of the application (possibly multiple times).</p>
  
  <pre><code>writer = new FileWriter(file);
  writer.write(".... what I want to print here.......");
  writer.close();
  </code></pre>
  
  <p>And then I send the file to the server with the following code.</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  HttpUriRequest request = new HttpPost(webAddress);
  MultipartEntity form = new MultipartEntity();
  client.getParams().setBooleanParameter("http.protocol.expect-continue", false);
  form.addPart(inputName, new FileBody(new File(filePath)));
  ((HttpEntityEnclosingRequestBase) request).setEntity(form);
  
  try {
      client.execute(request);    
      System.out.println("Connection Success");
  } catch (ClientProtocolException e) {
      throw e;
  } catch (IOException ee) {
      throw ee;
  } 
  </code></pre>