Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:40:35+00:00 2026-06-05T11:40:35+00:00

I am writing an application with which a file can be uploaded to a

  • 0

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?

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:

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br /

<input type="submit" value="Upload File" />
</form>

<?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";
?>
  <a href="<?php echo $to_file;?>"><?php echo $to_file;?></a>
<?php
  } else {
    echo "Unsuccessful upload";
  }
?> 

Below are snippets of my code for the android application.

public static File file = new File("/sdcard/upload.txt");
public static FileWriter writer;

This code is in a method I call during the running of the application (possibly multiple times).

writer = new FileWriter(file);
writer.write(".... what I want to print here.......");
writer.close();

And then I send the file to the server with the following 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;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:40:37+00:00Added an answer on June 5, 2026 at 11:40 am

    Is there someway to make the file name on the server to be different from what it is on the device sending it?

    Yes! All you have to do is change the $to_file to something else like:

    $dates = date('YmdHis');
    $to_file = "locationdata/" . $dates."." . basename($_FILES['uploadedfile']['name']);
    

    edit: added .”.”. so that there is a period separating the date/time from the original file name. Easier for you to explode it should the need arise later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application, which accesses Excel file with this code: RBTApplication = new
I'm writing an application which utilises tables which can be printed if the user
I'm writing an application which can copy files on a network share. Usually the
I'm writing an application which must log information pretty frequently, say, twice in a
I am writing an application which will search for a particular file or files
I'm writing a console application which is looking up information about SSIS packages in
Hey all, I'm writing an application which records microphone input to a WAV file.
I'm wondering about writing an application in Java which can synchronize files across my
I am writing a Java swing application which can store resumes (txt,pdf,docx,doc etc.) in
I'm writing an application that creates a Catalog of files, which can be attributed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.