到PHP我是一個初學者,我不知道如何去使用alamofire提交我的形象的陣列到我的數據庫。下面是我的代碼時,它的形式加載上傳與其他參數圖像的陣列在Xcode
override func viewDidLoad()
{
super.viewDidLoad()
// adding page image into the image square
for i in 1...3
{
var imgView : UIImageView!
imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
imgView.contentMode = .scaleAspectFit
imgView.tag = i
imgView.image = UIImage(named: "page.png")
imageArray.add(imgView)
}
videoView.isHidden = true
photoView.type = iCarouselType.coverFlow2
photoView.reloadData()
}
用戶選擇/拍照後圖像將取代page.png ..一切工作正常。下面是替換代碼
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
self.selectedImageView.image = chosenImage
imageArray.replaceObject(at: self.selectedImageView.tag-1, with: self.selectedImageView)
photoView.reloadData()
dismiss(animated:true, completion: nil)
}
至於提交的一部分,我有了解陣列和更重要的是提交一個數組PHP /數據庫的麻煩。請幫助我,因爲我不知道如何從這裏繼續。我需要提交圖像數組(最多3個圖像)以及表單中的其他參數。
@IBAction func submitAction(_ sender: Any)
{
let URL_Submit = "http://localhost/form.php"
let parameters: Parameters=[
"block":blockText.text!,
"category":catText.text!,
"description":descText.text!]
Alamofire.request(URL_Submit, method: .post, parameters: parameters).responseJSON
{
response in
//printing response
print(response)
let alertController = UIAlertController(title: "Success!", message:
"Your feedback has been submitted", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
我刪除了我的嘗試上載圖像在我submitAction bc它不工作。請幫助我,因爲我現在還沒有任何線索可以繼續。感謝您的時間
你能告訴我,我的答案是否解決了你的問題? –