Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:04:22+00:00 2026-06-09T10:04:22+00:00

I need to upload image from iphone application to PHP server for some processing

  • 0

I need to upload image from iphone application to PHP server for some processing on this image on server, then after the server is finished processing , i want to return the result image to the iphone application.

i already have the code for uploading, but i can’t get the result image from php server and display it within iphone application

Please help

These are the codes here:

The objective-c code for uploading:

NSString *urlString =[NSString stringWithFormat:@"http://192.168.1.3/TEST%20IPHONE/upload.php"] ;
    NSURL *nsurl =[NSURL URLWithString:urlString];  
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];   
    [request setURL:nsurl];  
    [request setHTTPMethod:@"POST"];

    self.editingImageView.image = nil;
  NSString * filename =  @"cartoonize.png";

    NSMutableData *body = [NSMutableData data];


    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    [request addValue:contentType forHTTPHeaderField:@"Content-Type"];

    // file
    NSData *imageData = UIImageJPEGRepresentation(self.EditingImage, 90);

    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];


     [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"userfile\"; filename=\"%@\"\r\n",filename]] dataUsingEncoding:NSUTF8StringEncoding]];

    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];



    // close form
    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    // set request body
    [request setHTTPBody:body];




    //return and test

    NSURLConnection * connection = [[NSURLConnection alloc] 
                                    initWithRequest:request
                                    delegate:self startImmediately:NO];

    [connection scheduleInRunLoop:[NSRunLoop mainRunLoop] 
                          forMode:NSDefaultRunLoopMode];
    [connection start];

Here the PHP code:

<?php
//echo $_FILES["userfile"]["size"];
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["userfile"]["name"]));


if ( ($_FILES["userfile"]["size"] < 200000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["userfile"]["error"] > 0)
    {
    //echo "Return Code: " . $_FILES["userfile"]["error"] . "<br />";
    }
  else
    {



      move_uploaded_file($_FILES["userfile"]["tmp_name"],
      "upload/" . $_FILES["userfile"]["name"]);


// some processing on the image and result image will be saved on this path upload/test.jpg

$file = "upload/test.JPG" ; 
$imageData = utf8_encode(file_get_contents($file));

echo $imageData;

}






  }
else
  {
  echo "Invalid file";
  }





?>

i get the data from NSUrlConnection delegate methods, so the result is in NSData object in my objective-c code, but i can’t get the image from this NSData object, What do you think guys?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:04:24+00:00Added an answer on June 9, 2026 at 10:04 am

    Are you implementing the NSURLConnection delegate methods that allow you to read the response of your request? If so, you should use an NSMutableData to accumulate the data being returned from your server (which is likely to be split across multiple delegate calls), then use a UIImage method such as imageWithData: to create the image on the client. For example:

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
        self.receivedImageData = [NSMutableData dataWithCapacity:[response expectedContentLength]];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        [self.receivedImageData appendData:data];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        UIImage *finishedImage = [UIImage imageWithData:self.receivedImageData];
        self.receivedImageData = nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to upload an image to a remote PHP server which expects the
I need to upload a given image using Amazon S3 I have this PHP:
In my iPhone application I need to upload images to a server. I don't
I am developing a server backend for my iphone application. I need to upload
Friend's , I need to upload an image from android device to Facebook server
I need to upload a single image to server. The project is using .NET
According to this question I succeeded to create upload image, but now I need
I'm in need of a generic image upload for a PHP site. Photos and
Is there any way a new image upload from a PHP form sent to
Hope you all will be fine. Actually i want to upload image files from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.