Ios4 在iphone中使用ASIHTTPRequest将图像上载到服务器
我必须从iphone上传图像到服务器,我使用的是AsitpRequest。我为上传七个文件设置了一个循环。但是,在只上传最后一个文件之后,有人会指出我错在哪里 我正在使用以下代码进行上传:Ios4 在iphone中使用ASIHTTPRequest将图像上载到服务器,ios4,asihttprequest,Ios4,Asihttprequest,我必须从iphone上传图像到服务器,我使用的是AsitpRequest。我为上传七个文件设置了一个循环。但是,在只上传最后一个文件之后,有人会指出我错在哪里 我正在使用以下代码进行上传: for (int i=1; i<8; i++) { NSString* filename = [NSString stringWithFormat:@"Photo%d.jpg", i]; NSString *path = [[NSHomeDirectory()
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"];
}
}
?>
for(int i=1;i
您正在覆盖request.file
,因此只上载最后一个。您必须对每个文件进行单独请求
或者您可以使用
[request addFile:(id)data with fileName:(NSString*)fileName和contentType:(NSString*)contentType forKey:(NSString*)key]
在一个请求中发送多个文件。您正在覆盖名为file的密钥,需要使用队列
做
[self-setNetworkQueue:[ASINetworkQueue]];
[[self-networkQueue]setDelegate:self];
对于(int i=1;iI必须上载多个文件(文件数量未确认)现在,如何设置请求,以便我们可以使用循环。嗨,我尝试了你的选项,但这次没有上传任何文件。我还附加了我的php文件代码的问题,如果这是造成一些问题。我认为php是好的。我想你需要使用一个队列-我会更新我的答案…获得以下错误“Method setNetworkQueue not found”和“Method networkQueue not found”。我已经添加了一个networkQueue.h文件。您是否已经在.h文件的接口中添加了一个networkQueue*networkQueue;,并在.m文件的.h和@Synthesis networkQueue;中添加了@property(非原子,保留)一个networkQueue*networkQueue
[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];