I'm developing an iOS app with Xcode and Swift.
I usually take this code to POST data to PHP:
let requestImage = NSMutableURLRequest(URL: NSURL(string: "http://example.com/postData.php")!)
requestData.HTTPMethod = "POST"
let postStringImage = "name=\(name.text!)&age=\(age.text!)"
requestData.HTTPBody = postStringImage.dataUsingEncoding(NSUTF8StringEncoding)
Now I want to post an image that's in a UIImageView to PHP: Can I simple do something like this? Code:
let requestImage = NSMutableURLRequest(URL: NSURL(string: "http://example.com/postImage.php")!)
requestData.HTTPMethod = "POST"
let postStringImage = "image=\(MyImage)"
requestData.HTTPBody = postStringImage.dataUsingEncoding(NSUTF8StringEncoding)
What do I have to do to make it working?
BTW:
I took this code to test my PHP script via browser:
<form action="postImage.php" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload">
<input type="submit" value="Upload Image">
</form>