2016-04-18 28 views
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"]; 
} 

誰能教我要上傳視頻。謝謝

+0

你可以用這樣的參數上傳圖片:http://stackoverflow.com/a/35238730/2125010 – fatihyildizhan

+0

我與圖片上傳完成與功能的源代碼我張貼,現在尋找視頻上傳@fatihyildizhan – DQueen

回答

0

圖像和視頻有什麼區別?它們都是二進制數據。可能的原因可能是php上傳的文件大小限制。 看看this manual和你的php.ini。必須有行

Maximum allowed size for uploaded files. 
upload_max_filesize = 10M 

; Must be greater than or equal to upload_max_filesize 
post_max_size = 10M 
+0

我的問題在於編程功能上傳視頻的速度,你能解釋我如何上傳視頻,我的意思是使用xcode快速形成的功能。即時通訊新的。感謝關於php中的限制大小 – DQueen