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

  • Home
  • SEARCH
  • 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 7020741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:21:28+00:00 2026-05-27T23:21:28+00:00

In my application i have to upload mutiple images to server using php. i

  • 0

In my application i have to upload mutiple images to server using php.

i am making an NSMutableArray *arrImages which hold’s my images which are selected from gallery.

suppose if i select two images and try to upload…..i am able to upload only one images which is selected last….i had check my for loop…it’s work fine …but i am not able to upload all two images…please help me out.

following is my code:

- (IBAction)btnTakePicture_Clicked:(id)sender
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.alpha=0.90;
    actionSheet.tag = 1;
    [actionSheet showInView:self.view]; 
    [actionSheet release];
    UIButton *btn = (UIButton *)sender;
    intButton = btn.tag;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (actionSheet.tag) 
    {
        case 1:
            switch (buttonIndex)
        {
            case 0:
            {               
#if TARGET_IPHONE_SIMULATOR

                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Camera not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
                [alert release];

#elif TARGET_OS_IPHONE  

                UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;  
                picker.delegate = self;  
                //picker.allowsEditing = YES;  
                [self presentModalViewController:picker animated:YES];
                [picker release];

#endif  
            }
                break;
            case 1:
            {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
                picker.delegate = self;  
                [self presentModalViewController:picker animated:YES];
                [picker release];
            }
                break;
        }
            break;

        default:
            break;
    }   
}


-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
    UIImage *img = [[UIImage alloc] initWithData:dataImage];



    if (intButton == 0) 
    {

        imgView1.image=img;

    }
    else if (intButton == 1) 
    {
        imgView2.image=img;
    }
    else if (intButton == 2) 
    {
        imgView3.image=img;
    }
    else if (intButton == 3)
    {
        imgView4.image=img;

    }
    else if (intButton == 4)
    {
        imgView5.image=img;
    }
    else if (intButton == 5)
    {
        imgView6.image=img;
    }
    else if (intButton ==6)
    {
        imgView7.image=img;
    }
    else if (intButton ==7)
    {
        imgView8.image=img;
    }

    [arrImages addObject:dataImage];
    //NSLog(@"%@",dataImage);
    [picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [self.navigationController dismissModalViewControllerAnimated:YES]; 
}

this is my upload code

-(IBAction)upload:(id)sender
{
    if ([arrImages count]>0) 
    {

        NSString *urlString = @"http://your url.com/upload/uploader.php";

        // setting up the request object now

        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
        [request setURL:[NSURL URLWithString:urlString]];
        [request setHTTPMethod:@"POST"];


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


        NSMutableData *body = [NSMutableData data];





        for (int i = 0; i < [arrImages count]; i++)
        {

            //NSMutableData *body = [NSMutableData data];

            //[body appendData:[arrImages objectAtIndex:i] withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:[NSString stringWithFormat:@"image%d", i + 1]];


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

            [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"image%d.jpg\"\r\n",i + 1] dataUsingEncoding:NSUTF8StringEncoding]];

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

            //[body appendData:[NSData dataWithData:imageData]];
            [body appendData:[arrImages objectAtIndex:i]];          
            [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
            // setting the body of the post to the reqeust

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

        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

        NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

        NSLog(@"%@",returnString);


    }

}

please help me out… i am try this from a long time..

  • 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-05-27T23:21:29+00:00Added an answer on May 27, 2026 at 11:21 pm

    Just a though, you SHOULD NOT use an Array to hold your UIImages. I have serious performance issues with that. What you should do, is to hold an array of paths to the images, on the moment you are going to upload the image, just use the path to get the image. In an iPhone 4 with more than 30 images from the gallery my app started to crash with memory warnings.

    Edit (Actual answer for your question):

    The problem is that before sending a new upload request, you should wait for the answer of the first. So:

    -> upload 1 -> WAIT -> Upload Complete -> upload 2 -> WAIT -> Upload Complete…

    Edit 2:

    Dimple Panchal is right, you should do it in a asynchronous way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a desktop application that needs to upload/download images to/from service computer over
I am able to have my application upload files via FTP using the FTPClient
I have a web application that needs to take a file upload from the
I have a simple iPhone application I am making that will upload pictures to
I have a server which consists of several Zend Framework application. I want to
I'm currenlty using Azure Blob to store files, and upload/download from ASP.Net Application hosted
we have a small flash component on our website/application to upload multiple files. This
I have Application written with GWT 1.7. I have one page where I upload
I have an application where users can upload video files of any size, and
I have an application where I allow users to upload files, mainly PDF and

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.