Android Upload Image To Server Using PHP MySql

Android Upload Image to Server Thumbnail

Android upload image to server using php mysql in this tutorial we are going to create a application which will Upload Image to Server. We will pickup image form gallery or form camera directly and will upload to hosting server. Our application will save image to specified folder on server and will save its path to Mysql server along with image name.So lets see how we can upload image to server using php mysql step by step.

Lets Start By Installing XAMPP Server

Before do anything firstly check you have XAMPP Server on your system or not. Alternatively you can use WAMP  (For Windows), LAMP (For Linux) and MAMP (For MAC).

If you don’t have XAMPP Server you can Download and Install form https://www.apachefriends.org/download.html

Start Apache and Mysql form XAMPP Control Panel.

xampp service start

Creating Database and Table

Open phpmyadmin to open this type localhost/phpmyadmin in Internet Browser and Create a Database and Table.

Creating Database

Creating Table

That’s it from Mysql Database part lets move to Php part.

Creating PHP Files

In this part we will create two files –

  1. config.php– This file will have Database Name, Username and Password.
  2. upload-image-to-server.php– This file receive image send form android application and store in server.

Open htdocs folder under C:\xampp and Create folder Android Upload Image .Under this folder create one upload folder. This upload folder will store all image send by android application.

Let’s create php files-

  • config.php-

  • upload-image-to-server.php-

We are done with php part now lets start java part.

Android Upload Image To Server Using Php MySql

Creating JAVA Files

  • Create a new project in Android Studio File–>New–>New Project.
  • Enter Application Name, Package Name, Select Empty Activity and click on finish.

start new android application

  • Our application will use Internet to send image to server and we will also need to use Camera access permission to use camera and permission to write into external storage to so firstly we need to add all these permission in AndroidManifest.xml file. Open your AndroidManifest.xml file and add following permission.

  • Now lets design our interface. We need one imageview which will show image which we will select from Gallery or Camera, one edittext box to get image name and two button one for selecting image and another for sending image to server.Open activity_main.xml file and write below code.

  • Now the main part open your MainActivity.java file. We will declare all edittext, button and required variables.By taping on Select Image button we need to chose between either we want image form gallery or from camera.After selecting image we can now send it image to server by using upload button.Complete code for MainActivity.java file-

Now Run your project . So that’s all for this Android Upload Image to Server Using Php MySql. If you will get any error or confusion regarding this Android Upload Image to Server Using Php MySql you can comment below.

Screen Shot

android upload image to server using php mysql

Download Source Code

Compete Code Download >>

Subscribe To Our YouTube Channel

 

Like Us On Facebook

 

 

RECENT POST

59 Comments

  1. i have run project but my image is not uploading. i got blank toast message.
    i am confused. help me.

    1. Make sure you are writing correct url. In my project it is “http://192.168.1.5/Android%20Upload%20Image/upload-image-to-server.php”.

      Check Yours..

  2. Dear Sumeet ,
    Why is the resolution smaller after uploading the photo ?
    Is there any way to keep original resolution ?
    Thanks !

    1. Hello..

      Change this to 100 for full resolution..

      //FixBitmap.compress(Bitmap.CompressFormat.JPEG, 40, byteArrayOutputStream);

  3. Dear Sumeet ,
    Why is the resolution smaller after uploading the photo ?
    Is there any way to keep original resolution ?
    Thanks !

    1. Hello..

      Change this to 100 for full resolution..

      //FixBitmap.compress(Bitmap.CompressFormat.JPEG, 40, byteArrayOutputStream);

  4. The script works perfectly thanks. However i would like to upload multiple images. Could you please assist. Thanks

  5. hi i want to add image with name family mobile and adress
    how i can add this data
    exampel student with name last name age mobile and his image
    tnx bro

  6. it show the message “Undefined index in’image_data’ and ‘image_tag'” in POST method what i should to fix it

  7. Thanks. But If I upload an image from the camera, the resolution is much lower and I have set the quality with 100. Contrary to the gallery that does not lower quality.

  8. at this line i m getting error //bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);

    The error is : java.lang.NullPointerException
    at android.graphics.Bitmap.compress

  9. Hello!
    When i run the project image uploading not works,

    Show a empty Toas please hellp me,
    I think the is corect.

  10. Excellent beat ! I wish to apprentice while you amend your
    web site, how could i subscribe for a blog web site?
    The account helped me a acceptable deal. I had been a
    little bit acquainted of this your broadcast offered bright
    clear idea

  11. I am trying to upload the images to mysql server using android studio the images are being uploaded to the database but when i display or try to re-upload the images are being repeated the select button is not taking the new image it is uploading the previous image itself which i have uploaded. I am unable to find the solution please guide me to do so as i am fresher.plz anwser me

  12. Good afternoon,
    I completed the upload image project. It worked perfect on the android emulator.
    By performing the test on the mobile device, no result is achieved.

    The device is on the same Wi-Fi network.
    For testing I typed the ip of the server into the browser and showed the message:

    Can not access this site
    Can not access:
    http://192.168.1.25/Android_Upload_Image/upload-image-to-server.php
    ERR_ADDRESS_UNREACHABLE

    ————————-
    Someone to help me solve this error. I’ll be very thankfull.

  13. Hi, what a great tutorial. But I get the message Undefined index: image_data from the php, and at the server, creates an empty file with the name given.

    Someone to help me solve this error. I’ll be very thankfull.

  14. while uploading image taken from camera.. The size resolution getting too small…Give me the solution for this problem???

  15. I am trying to upload the images to localhost using android studio the images are being uploaded to the database but when try to re-upload, the images are being repeated.it is not taking the new image, it is uploading the previous image itself which i have uploaded. I am unable to find the solution please guide me.

  16. You are a really persuasive writer. I can see this in your writeup. You’ve a way of writing compelling info that sparks significantly interest. gdedcdgbeedd

  17. I really like your blog.. very nice colors &amp theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to construct my own blog and would like to know where u got this from. thank you kebbgfaeagcd

  18. Hello, I completed the upload image project. It worked perfect on the android emulator.

    But if I use 4G net, it not work. How to solve?

  19. $ServerURL = “yourPath/$ImagePath”;

    I do not understand the meaning of yourpath. can you explain?

Leave a Reply

Your email address will not be published. Required fields are marked *