1

I am trying to upload a large file it causes me trouble. When I use smaller files to upload it works fine.

Here is the code in IOS I am using:

NSURL * url = [NSURL URLWithString:urlString];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostFormat:ASIMultipartFormDataPostFormat];
[request setPostValue:key forKey:@"key"];
[request setData:fileData withFileName:fileName andContentType:contentType forKey:key];
[request setRequestMethod:@"POST"];
[request setTimeOutSeconds:60000];
[request startSynchronous];

NSError *error = [request error];
if (!error)
{
    NSString *response = [request responseString];
    if (kShowLog)
        NSLog(@"%@", response);
    return [self objectWthString: response];
}
else
    if (kShowLog)
        NSLog(@"%@", error.debugDescription);
    return nil;

Here is the PHP code:

function microtime_float_string()
{
    list($usec, $sec) = explode(" ", microtime());
    return $sec . ($usec * 1000000);
}

$myTime = microtime_float_string();
srand(time());
$rand1 = rand();
srand($rand1);
$rand2 = rand();
$str = $myTime . $rand1 . $rand2 . '.aiff';

$arr = array();

$uploaddir = 'images/';      //Uploading to same directory as PHP file

//$file = basename($_FILES['userfile']['name']);
$file = $str;
$uploadfile = $uploaddir . $file;

if (!is_uploaded_file($_FILES['userfile']['tmp_name']))
{
    $arr["error"] = "File Upload Failed is_uploaded_file";
}
else if ($_FILES['userfile']['size']> 10000000)     //Limiting image at 10000K
{
    $arr["error"] = "File Size too Large";
}
else if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
{
    $url = SITE_URL . $uploadfile;
    $arr["message"] = "ok";
    $arr["url"] = $url;
}
else
{
    $arr["error"] = "File Upload Failed";
}
echo json_encode($arr);
Naveed Rafi
  • 2,503
  • 5
  • 32
  • 40

1 Answers1

0

php in OSX by default accepts 2 mb.

We have to update the php.ini file in order to accept files with bigger size.

The file is found under /etc/

edit the values of upload_max_filesize & post_max_size in php.ini

then restart it by running the following command

/etc/init.d/httpd restart
Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241