0

I am using the following code (with ASIHTTPRequest) to attempt to upload php files from my iPhone to my LAN MAMP server running on my Macbook Pro. My objective-c and my php seem to be in line, but the files are not uploading.

OBJECTIVE-C CODE

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
[path stringByAppendingPathComponent:[pieces objectAtIndex:indexPath.row]];

NSURL *url = [NSURL URLWithString:@"http://192.168.1.102:8888/upload.php"];


ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setFile:path forKey:@"file"];

PHP CODE

 <?php
$target = "uploads/";
$target = $target . basename( $_FILES['file']['name']) ;
$ok=1;
(move_uploaded_file($_FILES['file']['tmp_name'], $target));
?>

What is going wrong here?

Thanks,

James

4

4 回答 4

1

Apache httpd 进程是否有权限写入uploads/目录?尝试将其设置为/tmp/,看看是否有效?

我使用一个小的 php 脚本为AppSales-Mobile创建了一个备份解决方案。写到这里。我创建的 php 脚本如下所示。实际的邮政编码可以方法中查看- (void) startUpload

于 2010-03-07T10:23:06.903 回答
1

Xcode

[request setFile:path forKey:@"myfile"];

php

$uploaddir = '';
$uploadfile = $uploaddir.basename($_FILES['myfile']['name']);


move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile);
于 2012-11-22T06:09:34.220 回答
0

代码看起来不错。您确定您的服务器的 PHP 配置正在接受上传,并且 CSV 在大小限制范围内吗?

于 2010-03-07T09:48:54.560 回答
0

我知道这个回复可能为时已晚,无法具体帮助您,但以防其他人有同样的问题并查看这篇文章,我找到了解决方案。我遇到了这个确切的问题,我能找到的所有例子似乎都没有包含解决方案。但这很简单,你必须“开始”上传,就像下载一样。

简而言之,在您的 Objective-C 代码的末尾,您将添加以下行:

[request startSynchronous];
于 2012-04-09T05:49:06.553 回答