swift - Alamofire upload via .POST to PHP. Where is the uploaded file? -


i use .upload method upload php file on server , seems work (i 200 response)

upload(.post, config.uploadarbeitsauftragurl, urltofile!) 

how can access file in php file ? when want use $_file, need descriptor corresponding array-index , not able specify any.

i came across same problem today while prototyping something. hacky solution

swift

let filename = "myimage.png"  let documentspath = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] as! string let filepath = documentspath.stringbyappendingpathcomponent(filename) let fileurl = nsurl(fileurlwithpath: filepath)!  alamofire.upload(.post, "http://example.com/upload.php?filename=\(filename)", fileurl) 

upload.php

// file data $filedata = file_get_contents('php://input'); // sanitize filename $filename = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $_get["filename"]); // save disk file_put_contents($filename, $filedata); 

explanation

it seems alamofire sending file octet-stream, posting raw file data. can grab php://input don't filename. hacky solution send filename in query string.

remember, isn't "right" way. it's quick fix now


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -