PDA

View Full Version : file upload strange error




chhoda
Sep 29, 2010, 09:35 AM
[postbody appendData:[[NSString stringWithFormat:@"param1=%d&param2=%f&param3=%@", 1, 3.0, [txtDesc text]] dataUsingEncoding:NSUTF8StringEncoding]];

[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];



I am trying to upload a file with some additional info as post variables.

in php side i get the file upload properly, but when i do $param1 = $_POST['param1'] i get a blank.

what am i doing wrong ?

--CH



kainjow
Sep 29, 2010, 09:51 PM
I would suggest reviewing the samples here (http://www.cocoadev.com/index.pl?HTTPFileUpload), specifically the last chunk of code at the bottom.

I believe the problem is you need a Content-Disposition header for each name-value pair.