Come posso ottenere i valori dei parametri da Swift, il caricamento del file è già funzionante, ho provato $ _GET ["familyId"], ma non ha funzionato?Come ottenere i parametri da AFNETWORKING POST
Swift:
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",
]);
non hai aggiunto quell'ID all'URL. dovresti cercare in '$ _POST ['familyId']' –
@MarcB non capisco? guarda dove? – MasterWizard
Aspetta, fammi capire, stai usando il metodo HTTP POST, corretto? Perché dovresti provare a utilizzare GET e non usare ancora il POST? – Jeffrey