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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:21:51+00:00 2026-05-24T18:21:51+00:00

Well I am pretty new to both iphone and PHP development, and am trying

  • 0

Well I am pretty new to both iphone and PHP development, and am trying to simply post an image locally on to my webserver (i have setup the webserver already). From some reason, my PHP script is being executed, though the file is not being saved.

I am sure that this is the most basic problem here, but I just cant seem to find the problem. Would REALLY appreciate you guys’ help. Thanks!

My objective-c code:

UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"13.png"];

NSData *imageData = UIImageJPEGRepresentation(imageView.image, 90);
NSString *urlString = @"http://localhost/uploader.php";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setTimeoutInterval:60.0];
[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];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\";filename=\"myfile.jpg\"\r\n"] 
                  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 stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];
NSLog(@"%@",[[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil] encoding:NSUTF8StringEncoding]);

My PHP script:

<?php
$target = "./upload/";
$target = $target.basename( $_FILES['userfile']['name']) ;
$check = getimagesize($_FILES['userfile']['tmp_name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], './upload/')) {
    echo "YES";
}
 else
  echo "NO";

?> 

Those are the values that I get when printing these variables in PHP:

print_r($target);

./upload/myfile.jpg

print_r($check[0]);

320

print_r($_REQUEST);

Array
(
)


print_r($_FILES[userfile]);

Array
(
    [name] => myfile.jpg
    [type] => application/octet-stream
    [tmp_name] => /private/var/tmp/phpWJE4UC
    [error] => 0
    [size] => 8829
)

print_r($_FILES[name]): 

(empty)

print_r($_FILES[type]);

(empty)

print_r($_FILES[tmp_name]);

(empty)

print_r($_FILES[error]);

(empty)

print_r($_FILES[size]);

(empty)

print_r($_FILES);


Array
(
    [userfile] => Array
        (
            [name] => myfile.jpg
            [type] => application/octet-stream
            [tmp_name] => /private/var/tmp/phpMvJ4oR
            [error] => 0
            [size] => 8829
        )

)
  • 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-24T18:21:52+00:00Added an answer on May 24, 2026 at 6:21 pm

    Your move call is incorrect. You must specify a filename for the destination. You’ve only provided a directory, so the call fails. PHP will not create a filename for you, you must specify it yourself.

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], './upload/name_of_file_to_write')) {
                                                                      ^^^^^^^^^^^^^^^^^^^^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to both php and mysql. I have a txt file
I'm new to both android and game development and have been trying to create
I have an iPhone app with push notifications enabled and it's working pretty well.
I'm pretty new to APEX ( well, just started using it ~an hour ago),
The question seems pretty well formulated I have a virtual machine which implements only
I have an application that works pretty well in Ubuntu, Windows and the Xandros
I have a pretty well integrated OpenLayers map that I want to add photos
Ok, well I am pretty pretty pretty new to WPF and XAML, despite my
I'm new to memory managed code but I get the idea pretty well. On
I am new to both MVC as well as Entity Framework, but I want

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.