iphone - 上传图片 iPhone

标签 iphone ios nsurlconnection

我正在尝试使用 php 将 uiimage 从我的手机应用程序上传到服务器。但有些它不起作用。有人可以帮我吗?我的代码:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
            request.delegate = self;
            request.tag = 33;
            [request setPostValue:[NSString stringWithFormat:@"%@.png",responseString] forKey:@"name"];
            NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
            NSString *docDirectory = [sysPaths objectAtIndex:0];
            NSString *filePath = [NSString stringWithFormat:@"%@/MyImage.png", docDirectory];
            [request setFile:filePath forKey:@"photo"];

            [request startAsynchronous];
            [url release];
            NSError *error = [request error];
            if (!error) {
                NSString *response = [request responseString];
                NSLog(@"aResponse:%@",response);

            }

if(move_uploaded_file($_FILES['photo']['tmp_name'],$target_path)) {
    echo "The file ". basename( $_FILES['photo']['tmp_name'])." has been uploaded";
} 
else {
    echo "There was an error uploading the file, please try again!";
}

>

在 ASI 请求文件中使用 nszombie 进行调试时出现以下错误

* -[CFString release]:消息发送到已释放的实例 0xd1dfd80

最佳答案

不要释放 URL:请求将异步运行,因此在您释放它时它还没有完成。

关于iphone - 上传图片 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9719435/

相关文章:

iphone - 在 Storyboard中创建 IBOutlet 时出现问题

iphone - 如何判断用户是否触摸了工具栏项?

iphone - 检查 NSURLConnection 是否在 iphone 中不成功?

ios - CoreGraphics 和 CGI​​mageCreateWithImageInRect 的方向和原点

ios - 如何在tableView中隐藏indexPath处的分隔符?这意味着,删除特定的分隔符,而不是所有的分隔符

iOS POST 不适用于 HTTPS

ios - 如何为所有 api 链接创建一个单独的类并将该 api 调用到所有 View Controller

iphone - 无法识别的选择器发送到实例,iPhone 错误

iphone - Objective-C 中的位转换工具

iphone - 检查字符是否为回车