【发布时间】:2018-10-07 16:26:12
【问题描述】:
我使用 volley 和 php 创建了一个用于上传图像和文本的应用程序。这里是upload.php
include_once "koneksi.php";
class emp{}
$image = $_POST['image'];
$name = $_POST['name'];
//ini kode yang saya tambah yaitu item
$item = $_POST['item']
if (empty($name)) {
$response = new emp();
$response->success = 0;
$response->message = "Please dont empty Name.";
die(json_encode($response));
} else {
$random = random_word(20);
$path = "images/".$random.".png";
// sesuiakan ip address laptop/pc atau URL server
$actualpath = "http://192.168.43.137/android/upload_image/$path";
// saya tambah variabel item
$query = mysqli_query($con, "INSERT INTO volley_upload (photo,name,item) VALUES ($actualpath','$name','$item')");
if ($query){
file_put_contents($path,base64_decode($image));
$response = new emp();
$response->success = 1;
$response->message = "Successfully Uploaded";
die(json_encode($response));
} else{
$response = new emp();
$response->success = 0;
$response->message = "Error Upload image";
die(json_encode($response));
}
}
// fungsi random string pada gambar untuk menghindari nama file yang sama
function random_word($id = 20){
$pool = '1234567890abcdefghijkmnpqrstuvwxyz';
$word = '';
for ($i = 0; $i < $id; $i++){
$word .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
return $word;
}
mysqli_close($con);
?>
对于它的 .xml 部分,我使用 Fab 作为图像上传按钮和 2 个 TextView,即 editItem 和 editText。我还将 imageView 添加到要上传的图像中。在我在 XML 和 JAVA 中添加 textView editItem 项之前,应用程序运行良好,但是在我决定再添加一个 textView 上传(所以总共有 2 个 textview)后,数据没有成功发送到数据库,而之前上传1 张图片和 1 个 textView 描述,但我的目标是上传 1 张图片和 2 个 textView 描述,但未能上传 1 张图片和 2 个 textView(editText,editItem)
我该如何解决这个问题?我要上传 1 张图片和 2 个 textView(editText、editItem)
MainActivity.java = https://drive.google.com/open?id=1uxKxGmpRoPOJiKFLkXxGMxYrMgxBO3se activity_main.xml = https://drive.google.com/open?id=1xPso2Z_s0CV078UBUIzX1jjpfMG9k9_2
【问题讨论】:
-
你用php上传的命令在哪里?
-
我认为你必须阅读我的 MainActivity.java,我建议你阅读我的 upload.php
标签: java php mysql upload android-volley