-1
Ich versuche, PDF und Text von Android App an Server zu senden, gelang es mir, Text zu senden. das Problem ist, ich nicht pdf senden kann, ich weiß nicht, ob das Problem in Android-Code oder PHP-Code, so könnte jemand mir in diesem Problem helfen android Codesenden Sie PDF zum Server und speichern Sie es in der Datenbank
private class postData extends AsyncTask<String, Void, String> {
EditText email = (EditText) myView.findViewById(R.id.email);
EditText phone = (EditText) myView.findViewById(R.id.email);
String eemail=email.getText().toString();
String pphone=phone.getText().toString();
EditText first = (EditText) myView.findViewById(R.id.firstname);
EditText second= (EditText) myView.findViewById(R.id.lastname);
String firstname=first.getText().toString();
String lastname=second.getText().toString();
@Override
protected String doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://phone.tmsline.com/api/request_job");
String json = "";
String responseStr="";
String result="true";
try {
// Add your data
File uploadFile1 = new File("/sdcard/Download/Testing foundation.pdf");
FileBody fileBody = new FileBody(uploadFile1 , ContentType.DEFAULT_BINARY);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("cv",new FileBody(uploadFile1));
builder.addPart("email", new StringBody(eemail));
builder.addPart("phone", new StringBody(pphone));
builder.addPart("firstname", new StringBody(firstname));
builder.addPart("lastname", new StringBody(lastname));
HttpEntity entity = builder.build();
httppost.setEntity(entity);
try {
httpclient.execute(httppost);
// filetest();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
responseStr = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("HTTP Failed", e.toString());
}
return responseStr;
}
protected void onPostExecute(String responseStr) {
super.onPostExecute(responseStr);
String result="";
String test="";
String msg="msg";
int x=1;
Toast.makeText(getActivity(),responseStr,Toast.LENGTH_LONG).show();
try {
JSONArray pp=new JSONArray(responseStr);
result = pp.getString(x) Toast.makeText(getActivity(),result,Toast.LENGTH_LONG).show();
//result is key for which you need to retrieve data
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getActivity(),e.toString(),Toast.LENGTH_LONG).show();
}
}
PHP-Code
public function add_resume(Request $request){
$resume = new Resume;
$resume->first_name = $request->firstname;
$resume->last_name = $request->lastname;
$resume->phone = $request->phone;
$resume->email = $request->email;
$file = $request->file('cv');
$ext = $file->guessExtension();
$ext=".".$ext;
$filename=md5(time().mt_rand());
$file->move(storage_path('app/public/uploads'),$filename.$ext);
$resume->cv = $filename.$ext;
$resume->save();
return response()->json(['cv','1']);
}
Bitte erstellen Sie eine [mcve]. – dash2