如何从
Swift获取参数值,文件上传已经有效,我已经尝试了$_GET [“familyId”],但它没有用?
迅速:
let manager = AFHTTPRequestOperationManager() let url = "http://localhost/test/upload.PHP" var fileURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("test_1",ofType: "mov")!) var params = [ "familyId":locationd,"contentBody" : "Some body content for the test application","name" : "the name/title","typeOfContent":"photo" ] manager.POST( url,parameters: params,constructingBodyWithBlock: { (data: AFMultipartFormData!) in println("") var res = data.appendPartWithFileURL(fileURL,name: "fileToUpload",error: nil) println("was file added properly to the body? \(res)") },success: { (operation: AFHTTPRequestOperation!,responSEObject: AnyObject!) in println("Yes thies was a success") },failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in println("We got an error here.. \(error.localizedDescription)") })
PHP:
$target_dir = "uploads/"; $target_dir = $target_dir . basename($_FILES["fileToUpload"]["name"]); if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_dir)) { echo json_encode([ $user_info; "Message" => "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.","Status" => "OK",]);
你面临的问题是你看错了地方.正如您所说,您正在使用AFNetworking的POST方法来发布数据.强调POST. GET和POST是两个完全不同的东西. GET用于检索存储在网址中的值,例如www.example.com/example-get.PHP?key1=value1\u0026amp;key2=value2.您可以通过执行$_GET [‘key1’]来访问PHP中的不同值. POST是不同的东西.这与HTTP消息正文一起发送,并且无法在浏览历史记录或URL中看到.您可以使用$_POST [‘familyId’]访问您的数据.我建议稍微阅读一下,所以我会提供
this开始.
原文链接:https://www.f2er.com/php/136312.html祝你好运.