Note that there are some explanatory texts on larger screens.

plurals
  1. POImage is getting corrupted when posting to server from iPhone
    text
    copied!<p>Here is my code to upload image to php server but image is uploaded as corrupted image at server.Below is my code please tell me the issue..I have tried with cocoa rest client, image is uploading properly from it.</p> <pre><code> NSString *filename = @"connect-blue.png"; UIImage *image = [UIImage imageNamed:filename]; NSMutableURLRequest * request= [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"---------------------------14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *postbody = [NSMutableData data]; [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"profile_image\"; filename=\"%@\"\r\n",filename] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[postString dataUsingEncoding:NSUTF8StringEncoding]]; NSData *imagedata = UIImageJPEGRepresentation(image,1.0f); [postbody appendData:[NSData dataWithData:imagedata]]; [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; </code></pre> <p>Php code is here </p> <pre><code>if(!empty($_FILES)){ // $imgname=$_FILES['image']['name']; $a=pathinfo($imgname); if(!empty($a['extension'])){ $img_name=$a['filename']; $img_ext=$a['extension']; } else { $img_name=''; $img_ext=''; } $img_pre=mktime(); $image1=$img_pre."_".$imgname; move_uploaded_file($_FILES['image']['tmp_name'], "uploads/images/" . $image1); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload