how to send bitmap from android to php file
I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is
<?php
require "conn.php";
$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}
?>
I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?
php

add a comment |
I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is
<?php
require "conn.php";
$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}
?>
I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?
php

Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53
add a comment |
I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is
<?php
require "conn.php";
$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}
?>
I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?
php

I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is
<?php
require "conn.php";
$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}
?>
I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?
php

php

edited Jan 16 at 12:37


ankuranurag2
1,283418
1,283418
asked Nov 22 '18 at 0:01


Eman FateenEman Fateen
146
146
Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53
add a comment |
Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53
Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53
Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53
add a comment |
1 Answer
1
active
oldest
votes
first convert your bitmap into base64 and then send it to your server
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422129%2fhow-to-send-bitmap-from-android-to-php-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
first convert your bitmap into base64 and then send it to your server
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
|
show 1 more comment
first convert your bitmap into base64 and then send it to your server
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
|
show 1 more comment
first convert your bitmap into base64 and then send it to your server
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);
first convert your bitmap into base64 and then send it to your server
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);
answered Nov 22 '18 at 3:46


Har KalHar Kal
612414
612414
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
|
show 1 more comment
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?
– Luke Joshua Park
Nov 22 '18 at 3:52
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
he asked to send a bitmap in question. please read
– Har Kal
Nov 22 '18 at 3:53
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?
– Luke Joshua Park
Nov 22 '18 at 3:54
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead
– Har Kal
Nov 22 '18 at 3:57
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!
– Luke Joshua Park
Nov 22 '18 at 4:01
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422129%2fhow-to-send-bitmap-from-android-to-php-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show us what you've tried on the Android side?
– Luke Joshua Park
Nov 22 '18 at 3:53