php - send pdf to server and save it in database -


i try send pdf , text android app server , succeeded in sending text. problem can't send pdf , don't if problem in android code or php code me in problem android code

 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 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 key need 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']); } 

 public void onbindviewholder(final myattachmentviewholder holder, final int position) {         attachments=alist.get(position);         holder.filename.settext(attachments.get(fragmentassignmentdetails.file));         holder.viewbutton.setonclicklistener(new view.onclicklistener() {                                                  @override                                                  public void onclick(view v) {                                                      boolean internet = new internetcheck(contex).isonline();                                                      if (internet) {                                                          attachments=alist.get(position);                                                          string filename = attachments.get(fragmentassignmentdetails.file);                                                          bundle bundle = new bundle();                                                          filename.tolowercase();                                                          if (filename.endswith("jpeg") || filename.endswith("jpg") || filename.endswith("png") || filename.endswith("jpg") || filename.endswith("png") || filename.endswith("jpeg")) {                                                              bundle.putstring("filetype", "imagefile");                                                           } else if (filename.endswith("flv") || filename.endswith("mp4") || filename.endswith("mov")) {                                                              bundle.putstring("filetype", "videofile");                                                          } else {                                                              bundle.putstring("filetype", "noimage");                                                          }                                                          fragment fragment = new fragmentwebview();                                                          bundle.putstring("link", (url+filename));                                                          fragment.setarguments(bundle);                                                           android.support.v4.app.fragmenttransaction fragmenttransaction = ((android.support.v4.app.fragmentactivity) contex).getsupportfragmentmanager().begintransaction();                                                          fragmenttransaction.settransition(android.support.v4.app.fragmenttransaction.transit_fragment_open);                                                          fragmenttransaction.replace(r.id.container_body, fragment);                                                          fragmenttransaction.addtobackstack(null);                                                          fragmenttransaction.commit();                                                       } else {                                                          toast.maketext(contex, "no internet", toast.length_short).show();                                                       }                                                  }                                              }         );         holder.downloadbutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 attachments=alist.get(position);                 filename = attachments.get(fragmentassignmentdetails.file);                 string filelink = url+filename;                 sdcard = environment.getexternalstoragedirectory();                 directory = new file(sdcard.getabsolutepath() + "/" + contex.getstring(r.string.sdirname) + "/" + foldername + "/" + filename);                 string str = directory.getabsolutepath().tostring();                 if (directory.exists()) {                     intent intent = new intent(intent.action_view);                     if (str.endswith("pdf") || str.endswith("pdf")) {                         intent.setdataandtype(uri.fromfile(directory), "application/pdf");                         intent.setflags(intent.flag_activity_no_history);                         contex.startactivity(intent);                     } else if (str.endswith("docx") || str.endswith("doc")) {                         intent.setdataandtype(uri.fromfile(directory), "application/msword");                         contex.startactivity(intent);                         intent.setflags(intent.flag_activity_no_history);                     } else if (str.endswith("jpeg") || str.endswith("jpg") || str.endswith("png") || str.endswith("jpg") || str.endswith("png") || str.endswith("jpeg")) {                         intent.setdataandtype(uri.fromfile(directory), "image/*");                         intent.setflags(intent.flag_activity_no_history);                         contex.startactivity(intent);                     }                     else{                         toast.maketext(contex, "app not found", toast.length_short).show();                     }                 }                 else {                     internet = new internetcheck(contex).isonline();                     if (internet) {                         task = (downloadfilefromurl) new downloadfilefromurl(contex).execute(filelink);                     }                     else {                         toast.maketext(contex, "no internet", toast.length_short).show();                     }                 }               }         });     } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -