简体   繁体   English

从ios上传大文件

[英]uploading large file from ios

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: 这是我正在使用的IOS中的代码:

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: 这是PHP代码:

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);

php in OSX by default accepts 2 mb . 默认情况下,OSX中的php接受2 mb的内存

We have to update the php.ini file in order to accept files with bigger size. 我们必须更新php.ini文件才能接受更大尺寸的文件。

The file is found under /etc/ 该文件位于/ etc /下

edit the values of upload_max_filesize & post_max_size in php.ini 在php.ini中编辑upload_max_filesizepost_max_size的值

then restart it by running the following command 然后通过运行以下命令重新启动它

/etc/init.d/httpd restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM