So this tutorial using two projects, 1 PHP project and the other one is Android project. Don't forget to create your database to store the image that received from Android.
Image will be send from android by send its json to server. In php project, we also create a file that handle json from mobile (android).
We will save the file of image in the directory inside the php project. In database we just store the path of the image from php project.
- Users choose image obama.jpg from their android
- In PHP project, there is a directory named imagefromandroid.
- In database, just store its path, so it's become : imagefromandroid/obama.jpg.
In this project i just create simple database, only one table. Please adjust your project and your database.
Create a directory that used to save the file of image that received from android. Take a look at the following image
I above figure, i create a directory where image from mobile android will stored name imagefromandroid. Also, we will use two php classes, Connection.php and insertImageFromMobile.php.
This file used to connect your PHP Project to your database. The code look like the follows :
This class used to handle data that received from mobile in json form. The code is look like the follows :
There are several classes and xml files that we create in order to able to send image to the server or database.
This class created for handle response of retrofit. In other word, we able to see request process of retrofit to the endpoint.
This class will handle response message of request. The response message that will shown by this class are success or failed.
This class is an interface. In this class will declare endpoint of BASE URL.
This class contains the BASE URL that used in this project. And also in this class contains initialized of the retrofit
All class or method that used to send image to the server will called in this class. Full code of MainActivity :
Okay, that's all. Hope it helps you to learn how to insert image from android to database.