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 7754141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:14:01+00:00 2026-06-01T12:14:01+00:00

I’ve been trying to follow some examples for uploading data to a website. I

  • 0

I’ve been trying to follow some examples for uploading data to a website. I want to save the message as a .txt file. Any ideas what to do here?

- (IBAction)sendSerializedGreeting:(id)sender;
{
    NSString *message;
    message =@"Here we go for a test message.";
    // Show a loading indicator
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    NSString *greetingURL = [NSString stringWithFormat:@"http://www.site.com/upload.php"];

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:greetingURL]
             cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];  

    NSDictionary *headerFieldsDict = [NSDictionary dictionaryWithObjectsAndKeys:@"text/xml; charset=utf-8", @"Content-Type", nil];

    [theRequest setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
    [theRequest setAllHTTPHeaderFields:headerFieldsDict];
    [theRequest setHTTPMethod:@"POST"];

    // create the connection with the request and start loading the data
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (theConnection == nil)
    {
        NSLog(@"Failed to create the connection");
    }
}

Here is the upload.php file. I’m assuming the issue is with this but not sure. I don’t know where the filename gets set in the example above. This code was used from somewhere else.

<?php
$uploaddir = './';      //Uploading to same directory as PHP file

$file = basename($_FILES['userfile']['name']);

$uploadFile = $file;
$randomNumber = rand(0, 99999); 
$newName = $uploadDir . $randomNumber . $uploadFile;

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
    echo "Temp file uploaded.";
} else {
    echo "Temp file not uploaded.";
}

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) {

}
?>
  • 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-01T12:14:02+00:00Added an answer on June 1, 2026 at 12:14 pm

    I am sending a image to server through this code …. use for your text file or any type of multiform data

         NSString *strUrl=@"http://www.site.com/upload.php";
            NSLog(@"%@",strUrl);
            NSURL *url=[NSURL URLWithString:strUrl];
    
            NSMutableURLRequest *request = [NSMutableURLRequest  requestWithURL:url
                                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                                timeoutInterval:130.0];
    
            // file name of user picture
    // I am sending a image to server
            NSString *fileName=[[eMailTxtField.text stringByReplacingOccurrencesOfString:@"@" withString:@"-"]  stringByAppendingString:@".jpg"];
            //image data
            UIImage *userImage=imgUser.image;
            NSData *imageData =UIImageJPEGRepresentation(userImage, 90);
    
            NSMutableData *myRequestData = [[NSMutableData alloc] init];
            [myRequestData appendData:[NSData dataWithBytes:[postData UTF8String] length:[postData length]]];
    
    
            NSString *boundary = [NSString stringWithString:@"--"];
            NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
            [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
            [myRequestData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
            [myRequestData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"uploadfile\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
            [myRequestData appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
            [myRequestData appendData:[NSData dataWithData:imageData]];
            [myRequestData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
            [ request setHTTPMethod: @"POST" ];
    
            [ request setHTTPBody: myRequestData ];
            NSURLResponse *response;
            NSError *error;
            NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&error];
            if (!error && returnData) {
                NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
                [self registerWithJsonString:content];
            }
            else{
                [self showServerNotFoundError];
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to follow some WCF Data Services examples and have the
I've been trying to follow the top Google results for ASP.NET + Flexigrid for
I've been trying to follow every single tutorial and thread there is, i jast
I've been working on an application and I was trying to follow this site
I have been trying to write a custom .screenrc file TEST as follows startup_message
I'm trying to use Selenium (in Python) to extract some information from a website.
I have been trying to follow the instructions in the answer to this question
I have been trying to follow the few tutorials on how to create a
PROBLEM: Ok, I've been TRYING to follow the sample code on the MySQL Forge
Been trying to find a working implementation of a WPF listview (or listbox) where

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.