ios - Image Upload: Swift 3 to PHP using alamofire - How would you include an image in the code I provided? -
i know has been asked looking specific answer fit code have. appreciated. have been stuck on months.
i have register form inside tableview cell textfields , profile image user can select. using alamofire , php backend. php set receive data , image. able select image , able submit form , pass data through. problem having have no idea how include image when submitted.
code below. there no errors btw.
select image - works fine
@ibaction func image(_ sender: uibutton) { let cell = sender.superview?.superview as! tableviewcell func imagepickercontroller(_ picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string: anyobject]) { cell.profileimage.image = info[uiimagepickercontrolleroriginalimage] as! uiimage picker.dismiss(animated: true, completion: nil) } func imagepickercontrollerdidcancel(_ picker: uiimagepickercontroller) { picker.dismiss(animated: true, completion: nil) } let optionmenu = uialertcontroller(title: nil, message: "profile image", preferredstyle: .actionsheet) // let chooseaction = uialertaction(title: "choose image", style: .default, handler: { (alert: uialertaction!) -> void in self.imagepickercontroller.delegate = self self.imagepickercontroller.sourcetype = uiimagepickercontrollersourcetype.photolibrary self.present(self.imagepickercontroller, animated: true, completion: nil) }) // let takeaction = uialertaction(title: "take image", style: .default, handler: { (alert: uialertaction!) -> void in self.imagepickercontroller.delegate = self self.imagepickercontroller.sourcetype = .camera self.present(self.imagepickercontroller, animated: true, completion: nil) }) // let cancelaction = uialertaction(title: "cancel", style: .cancel, handler: { (alert: uialertaction!) -> void in print("cancelled") }) // optionmenu.addaction(chooseaction) optionmenu.addaction(takeaction) optionmenu.addaction(cancelaction) self.present(optionmenu, animated: true, completion: nil) } func imagepickercontroller(_ picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : any]) { var cell = tableview.cellforrow(at: indexpath.init(row: 0, section: 0)) as! tableviewcell let imgtemp = info[uiimagepickercontrolleroriginalimage] as? uiimage cell.profileimage.image = imgtemp picker.dismiss(animated: true, completion: nil) }
submit form data how include image selected?
@ibaction func submit(_ sender: uibutton) { let cell = sender.superview?.superview as! tableviewcell var variable1 = cell.field01.text! var variable2 = cell.field02.text! var variable3 = cell.field03.text! let url = "http://www.website.com/register.php?variable1=\(variable1)&variable2=\(variable2)&variable3=\(variable3)” let urlencodedstring = registerurl.replacingoccurrences(of: " ", with: "%20") self.parsejson(url: urlencodedstring) }
json - alamofire
func parsejson(url : string){ alamofire.request(url).responsejson(completionhandler: { response in self.parsedata(jsondata: response.data!) })} func parsedata(jsondata : data){ { var readablejson = try jsonserialization.jsonobject(with: jsondata, options: .mutablecontainers) as! jsonobject if let signjson = readablejson["register"] as? [jsonobject] { in 0..<signjson.count { let json = signjson[i] let parsestatus = json["sendstatus"] as! string let parsemessage = json["sendmessage"] as! string if parsestatus == "error" { self.alert(“error”) } else if parsestatus == "success" { performsegue(withidentifier: "register01=>register02", sender: self)} }}} catch {print(error)} }
Comments
Post a Comment