使用PHP和Swift 2上传图片?

时间:2016-06-04 04:26:21

标签: php mysql swift swift2

这是我目前的代码:

let request = NSMutableURLRequest(URL: NSURL(string: "http://www.example.com/upload.php"))
request.HTTPMethod = "POST"
let postString = "name=\(name)&id=\(id)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)

let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
    data, response, error in

    if error != nil {
        print("error=\(error)")
        return
    }

    let response = String(data: data!, encoding: NSUTF8StringEncoding)
}
task.resume()

我的图片是myImage.image

如何将图片上传添加到上面的代码中?

1 个答案:

答案 0 :(得分:0)

尝试这个我希望它会有所帮助!!

Ctrl+B