Добрый день! Сломал голову. пытаюсь из приложения сохранить фото на сервер. В общем какая то беда.
код swift
import UIKit
class InViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
private let uploadImage = "https://site/upload_img/upload2.php"
override func viewDidLoad() {
super.viewDidLoad()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
{
imageView.contentMode = .scaleToFill
imageView.image = pickedImage
otmetkaBT.isHidden = false
guard let urll = URL(string: "\(uploadImage)") else { return }
var request = URLRequest(url: urll)
request.httpMethod = "POST"
request.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type")
guard let imageProperties = ImageProperties(withImage: pickedImage, forKey: "image") else { return }
request.httpBody = imageProperties.data
print(imageProperties.data)
print(request)
let session = URLSession.shared
session.dataTask(with: request) {
data, response, error in
if let response = response {
print(response)
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: [])
print(json)
}catch
{
print(error)
}
}.resume()
}
picker.dismiss(animated: true, completion: nil)
}
код php
<?php $target_dir = "uploads/";if(!file_exists($target_dir)) { mkdir($target_dir, 0777, true); } $target_dir = "/" . $target_dir . "/" . basename($_FILES["image"]); if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_dir)) { echo json_encode([ "Message" => "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.", "Status" => "OK", "userId" => $_REQUEST["userId"] ]); } else { echo json_encode([ "Message" => "Sorry, there was an error uploading your file.", "Status" => "Error" ]); } ?>В чем проблема?