使用iphone中的ASIHTTPRequest将图像上传到服务器 [英] Uploading images to server using ASIHTTPRequest in iphone

查看:96
本文介绍了使用iphone中的ASIHTTPRequest将图像上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将图像上传到服务器表单iphone我正在使用ASIHTTPRequest。我已经设置了一个上传七个文件的循环。但是在执行后只上传了最后一个文件,可以指出我错误的地方。

I have to upload images to server form iphone I am using ASIHTTPRequest for this. I have set a loop for uploading seven files. But after the executing only last file is uploaded can some one point out where I am getting it wrong.

我使用以下代码进行上传:

I am using the below code for uploading :

for (int i=1; i<8; i++) 
    {
        NSString* filename = [NSString stringWithFormat:@"Photo%d.jpg", i];
        NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:filename];
        [request setFile:path forKey:[NSString stringWithFormat:@"file"]];
    }

    [request startAsynchronous];
    [resultView setText:@"Uploading data..."];

My Php file code is as following : 



 <?php
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

        if (file_exists("vinay/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "vinay/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "http://serverpath" . $_FILES["file"]["name"];
          }
        }
    ?> 


推荐答案

你正在覆盖名为file&的密钥。你需要使用一个队列。

You're overwriting the key called file & you need to use a queue.

[self setNetworkQueue:[ASINetworkQueue queue]];
[[self networkQueue] setDelegate:self];

for (int i=1; i<8; i++) 
{
    NSString* filename = [NSString stringWithFormat:@"Photo%d.jpg", i];
    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:filename];
    [request setFile:path forKey:[NSString stringWithFormat:@"file%d", i]];
    [[self networkQueue] addOperation:request];
}
[[self networkQueue] go];

这篇关于使用iphone中的ASIHTTPRequest将图像上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆