0
我想上傳視頻和圖像在服務器上迅速使用Json和PHP。我使用更多參數上傳圖像和視頻。我可以在服務器上傳圖片,但不能上傳視頻。如何上傳視頻和圖像在服務器在斯威夫特
func myImageUploadRequest(){
let myUrl = NSURL(string: "http://192.168.3.52/cobaupload2/index.php");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
let param = [
"firstName" : "TESTNAME",
"lastName" : "TESTNAMELAST",
"userId" : "10"
]
let boundary = generateBoundaryString()
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
let imageData = UIImageJPEGRepresentation(myImageView.image!, 1)
if(imageData==nil) { return; }
request.HTTPBody = createBodyWithParameters(param, filePathKey: "file", imageDataKey: imageData!, boundary: boundary)
myActivityIndicator.startAnimating();
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)", terminator: "")
return
}
print("******* response = \(response)", terminator: "")
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("****** response data = \(responseString!)")
//let json:NSDictionary = (try! NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers)) as! NSDictionary
dispatch_async(dispatch_get_main_queue(),{
self.myActivityIndicator.stopAnimating()
self.myImageView.image = nil;
});
}
task.resume()
}
和PHP文件
<?php
if (move_uploaded_file($_FILES['file']['tmp_name'], "image.png")) {
echo "File uploaded: ".$_FILES["file"]["name"];
}
誰能教我要上傳視頻。謝謝
你可以用這樣的參數上傳圖片:http://stackoverflow.com/a/35238730/2125010 – fatihyildizhan
我與圖片上傳完成與功能的源代碼我張貼,現在尋找視頻上傳@fatihyildizhan – DQueen