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

查看:36
本文介绍了在 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.

我使用以下代码上传:

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天全站免登陆