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

  • Home
  • SEARCH
  • 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 8686533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:52:31+00:00 2026-06-12T22:52:31+00:00

I would like to upload a file from android device to server using php.

  • 0

I would like to upload a file from android device to server using php. Also I want to send the name of the file to a database with a WHERE statement. I can upload my file, but I can’t send the WHERE statement, I don’t know where and how to put it in the android source.

Here’s my php code:

<form action="FileUp.php" method="post" enctype="multipart/form-data">
</form>

<?php

mysql_connect('localhost','root','root');
mysql_select_db('db');

$target_path  = "./";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$file = basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "The file ".  basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
$ident=addslashes($_POST['ident']);

mysql_query ("UPDATE table SET column = CONCAT(column,'$file') WHERE id = '$ident'");

?>

And here’s the java code:

@Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            String exsistingFileName = file.getText().toString();
            String lineEnd = "\r\n";
            String twoHyphens = "--";
            String boundary = "*****";
            try {
                // ------------------ CLIENT REQUEST

                Log.e(Tag, "Inside second Method");

                FileInputStream fileInputStream = new FileInputStream(new File(
                        exsistingFileName));

                // open a URL connection to the Servlet

                URL url = new URL(urlString);

                // Open a HTTP connection to the URL

                conn = (HttpURLConnection) url.openConnection();

                // Allow Inputs
                conn.setDoInput(true);

                // Allow Outputs
                conn.setDoOutput(true);

                // Don't use a cached copy.
                conn.setUseCaches(false);

                // Use a post method.
                conn.setRequestMethod("POST");

                conn.setRequestProperty("Connection", "Keep-Alive");

                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);

                DataOutputStream dos = new DataOutputStream(conn.getOutputStream());

                dos.writeBytes(twoHyphens + boundary + lineEnd);
                dos
                        .writeBytes("Content-Disposition: post-data; name=uploadedfile;filename="
                                + exsistingFileName + "" + lineEnd);
                dos.writeBytes(lineEnd);

                Log.e(Tag, "Headers are written");

                // create a buffer of maximum size

                int bytesAvailable = fileInputStream.available();
                int maxBufferSize = 1000;
                // int bufferSize = Math.min(bytesAvailable, maxBufferSize);
                byte[] buffer = new byte[bytesAvailable];

                // read file and write it into form...

                int bytesRead = fileInputStream.read(buffer, 0, bytesAvailable);

                while (bytesRead > 0) {
                    dos.write(buffer, 0, bytesAvailable);
                    bytesAvailable = fileInputStream.available();
                    bytesAvailable = Math.min(bytesAvailable, maxBufferSize);
                    bytesRead = fileInputStream.read(buffer, 0, bytesAvailable);
                }

                // send multipart form data necesssary after file data...

                dos.writeBytes(lineEnd);
                dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                // close streams
                Log.e(Tag, "File is written");
                fileInputStream.close();
                dos.flush();
                dos.close();

            } catch (MalformedURLException ex) {
                Log.e(Tag, "error: " + ex.getMessage(), ex);
            }

            catch (IOException ioe) {
                Log.e(Tag, "error: " + ioe.getMessage(), ioe);
            }

            try {
                BufferedReader rd = new BufferedReader(new InputStreamReader(conn
                        .getInputStream()));
                String line;
                while ((line = rd.readLine()) != null) {
                    Log.e("Dialoge Box", "Message: " + line);
                }
                rd.close();

            } catch (IOException ioex) {
                Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex);
            }

Please help where do I need to put my ident string to send to the php side!
Thanks a lot!

  • 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-12T22:52:32+00:00Added an answer on June 12, 2026 at 10:52 pm

    You can upload the Images via the MultipartEntity.

    MultipartEntity, part of HttpMime 4.0 and later. Allows you to put multiple parts, separated by boundary strings and encoded using given charset, into httppost request.

    For more info and how to use Multipart, see this and this.

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

Sidebar

Related Questions

I would like to send file from client to server and be able do
I would like to upload file from the client to the server with a
I would like to know how to upload a file from ActionScript 3 (From
I would like to know how to upload a WAR file separated from its
I would like to upload a directory from an EMR local file system to
I would like to upload a file from an html form, post it to
I would like to upload couple of images and a text file from iphone
Hey. I would like to upload a file and then parse it. Because parsing
I would like to have a nice easy to use file upload system on
I would like to upload files just like google mail does. I would want

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.