- Home /
How to grab POST image data from WWWForm on server?
Hello!
My code should be working. I use Prime31 to get a photo from the iOS device photo library, which is then supposed to be uploaded using WWWForm to my server for processing. The code below is working, I am able to use print_r($_POST);
on the server to see the text field (Email) that I've submitted. However there's no entry in the array for any data.
How does a guy capture the data on the server? Thanks for any tips!
function UploadPhoto(fileName : String){
var screenShotURL = URL_OF_SERVER_PHP_PAGE;
var bytes = System.Text.Encoding.UTF8.GetBytes(fileName);
var form = new WWWForm();
form.AddField("userEmail", PlayerPrefs.GetString("Last Email"));
form.AddBinaryData("fileUpload", bytes, "newPhoto.jpg", "image/jpg");
// Upload to a cgi script
var w = WWW(screenShotURL, form);
yield w;
if (!String.IsNullOrEmpty(w.error))
print(w.error);
else
print ("Results: " + w.text);
}
More info, the code below on my server should tell me about any files, I'd think. However it results in:
Results: Upload: Type: Size: 0 Kb Temp file:
echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";
Comment
Best Answer
Answer by infinitypbr · Feb 13, 2015 at 08:17 PM
All the above works, except the first field in AddBinaryData should just be "file".
Now on to the next problem.