我想从android应用程序上传图片,但是它在第13行的xampp \ htdocs \ CityHero \ user_registration.php中生成未定义索引错误:user_pic ...
我无法理解与此错误相关的问题。.
user_registration.php
GPL Ghostscript 9.25: UTF16BE text string detected in DOCINFO cannot be represented
in XMP for PDF/A 1, discarding DOCINFO
Processing pages 1 through 56.
Page 1
GPL Ghostscript 9.25: Setting Overprint Mode to 1
not permitted in PDF/A-2, overprint mode not set
?>
这是我的Android Studio上传代码。
<?php
require "config.php";
$obj = new config();
$er = 0;
$filename = "";
$return = array();
if (isset($_POST["user_name"]) && isset($_POST["user_email"]) && isset($_POST["user_city"]) && isset($_POST["user_area"]) && isset($_POST["username"]) && isset($_POST["password"])) {
if ($_FILES['user_pic']["name"] != "") {
$type = "." . pathinfo($_FILES['user_pic']['name'],PATHINFO_EXTENSION);
if ($type == ".jpeg" || $type == ".png" || $type == ".jpg" || $type == ".bmp") {
$filename = date("d-m-Y-H-i-s").$type;
$file_server_path = $obj->SERVERPATH . basename($filename);
move_uploaded_file($_FILES['user_pic']['tmp_name'], $file_server_path);
$return["STATUS"] = true;
$return["MSG"] = "FILE UPLOADED SUCCESSFULLY...";
}else{
$er = 1;
echo "Error!!!Please Check Code Once Again....";
// echo $return["STATUS"] = false;
// echo $return["MSG"] = "ERROR!!! Please Check Code once again....";
}
if ($er == 0) {
$insData["user_name"] = $_POST["user_name"];
$insData["user_email"] = $_POST["user_email"];
$insData["user_city"] = $_POST["user_city"];
$insData["user_area"] = $_POST["user_area"];
$insData["username"] = $_POST["username"];
$insData["password"] = md5($_POST["password"]);
$insData["create_date"] = $obj->current_date;
$insData["modify_date"] = $obj->current_date;
$insData["remote_ip"] = $obj->remote_ip;
$insData["user_pic"] = $filename;
$result = $obj->myInsdata("users_registration",$insData);
if ($result) {
echo "Insertion Succesfull";
// echo $return["STATUS"] = true;
// echo $return["MSG"] = "INSERTED SUCCESSFULLY...";
}else{
echo "Error!!!Please Check Code Once Again....";
// echo $return["STATUS"] = false;
// echo $return["MSG"] = "INSERTED NOT SUCCESSFULL...";
}
}
}
}else{
echo "Error!!!Please Check Code Once Again....";
// echo $return["STATUS"] = false;
// echo $return["MSG"] = "FIELD IS NOT SET..";
}
//echo json_encode($return);
请帮助我如何将图像从Android应用程序上传到Mysql数据库...
答案 0 :(得分:0)
您可以使用Gotev Upload Service
上传图片在gradle依赖中
dependencies {
implementation "net.gotev:uploadservice:3.4.2"
}
然后参加活动
public void uploadMultipart(final Context context) {
try {
String uploadId =
new MultipartUploadRequest(context, "your URL here")
.addFileToUpload("data.getData() here", "user_pic")
.addParameter("user_name", "param value")
.addParameter("user_email", "param value")
.addParameter("user_city", "param value")
.addParameter("user_area", "param value")
.addParameter("username", "param value")
.addParameter("password", "param value")
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload();
} catch (Exception exc) {
Toast.makeText(context, "Exception: "+exc.getMessage(), Toast.LENGTH_SHORT).show();
}
}