ios – 使用MKNetworking图像上传PHP获取内部错误500

ios – 使用MKNetworking图像上传PHP获取内部错误500,第1张

概述我已经从使用正常的方式上传图像(Didnt让它正常工作)到使用MKNetworking来协助我上传过程,我使用这种方式,因为我发现我得到更好的错误响应和它帮助解决我的问题.我收到了一个错误读取的NSLog响应 2013-05-03 10:52:25.961 atmebeta[2420:907] Returning num rows2013-05-03 10:52:25.967 atmebeta[ @H_301_2@ 我已经从使用正常的方式上传图像(DIDnt让它正常工作)到使用MKNetworking来协助我上传过程,我使用这种方式,因为我发现我得到更好的错误响应和它帮助解决我的问题.我收到了一个错误读取的NSLog响应

2013-05-03 10:52:25.961 atmebeta[2420:907] Returning num rows2013-05-03 10:52:25.967 atmebeta[2420:907] Returning num sections2013-05-03 10:52:34.607 atmebeta[2420:907] -[MKNetworkEngine reachabilityChanged:] [line 198] Server [atmeapp.com] is reachable via Wifi2013-05-03 10:52:37.066 atmebeta[2420:907] -[MKNetworkOperation operationFailedWithError:] [line 1345] FrIDay,May 3,2013,10:52:37 AM Pacific Daylight TimeRequest-------curl -X POST "http://atmeapp.com/addavatar.PHP" -d "email=ooo@ooo.com"--------Response--------<!DOCTYPE HTML PUBliC "-//W3C//DTD xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml"><head><Meta http-equiv="Content-Type" content="text/HTML; charset=utf-8" /><Title></Title><link rel="stylesheet" type="text/CSS" href="CSS/main.CSS" /><!--[if lt IE 9]>  <link rel="stylesheet" type="text/CSS" href="CSS/IE_8.CSS" /><![endif]--></head><body>    <div ID="block_error">        <div>            <h2>Error 500 Internal Server Error</h2>            <p>The web server is misconfigured please contact aaron@teknologenIE.com</p><p>Please try to access the site later.</p>        </div>    </div></body></HTML>,[The operation Couldn’t be completed. (NSURLErrorDomain error 500.)]2013-05-03 10:52:37.072 atmebeta[2420:907] Error Domain=NSURLErrorDomain Code=500 "The operation Couldn’t be completed. (NSURLErrorDomain error 500.)" UserInfo=0x1d993d40 {Accept-Ranges=bytes,Server=Apache,Content-Length=693,Content-Type=text/HTML,Date=Fri,03 May 2013 17:52:34 GMT}2013-05-03 10:52:37.102 atmebeta[2420:907] -[MKNetworkOperation operationFailedWithError:] [line 1353] State: 0

我可以通过HTML表单成功上传图像,所以我确定我的PHP.ini很好,我允许上传的方式更多,然后我要求在我的iPhone上传.

fileUploadDemoVIEwController.h

////  fileUploadDemoVIEwController.h//  fileUploader////  Created by Michael Roling on 5/7/12.//  copyright (c) 2012 NA. All rights reserved.//#import <UIKit/UIKit.h>#import "fileUploadEngine.h"@interface fileUploadDemoVIEwController : UIVIEwController <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>@property (strong,nonatomic) fileUploadEngine *flUploadEngine;@property (strong,nonatomic) MKNetworkOperation *flOperation;@end

fileUploadDemoVIEwController.m

////  fileUploadDemoVIEwController.m//  fileUploader////  Created by Michael Roling on 5/7/12.//  copyright (c) 2012 NA. All rights reserved.//#import "fileUploadDemoVIEwController.h"#import "MyClass.h"@interface fileUploadDemoVIEwController ()@end@implementation fileUploadDemoVIEwController@synthesize flUploadEngine = _flUploadEngine;@synthesize flOperation = _flOperation;- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    // Do any additional setup after loading the vIEw,typically from a nib.}- (voID)vIEwDIDUnload{    [super vIEwDIDUnload];    // Release any retained subvIEws of the main vIEw.}- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation{    return (interfaceOrIEntation != UIInterfaceOrIEntationPortraitUpsIDeDown);}- (IBAction)uploadPhoto:(ID)sender {    UIActionSheet *photoSourcePicker = [[UIActionSheet alloc] initWithTitle:nil                                        delegate:self cancelbuttonTitle:@"Cancel"                                        destructivebuttonTitle:nil                                        otherbuttonTitles:  @"Take Photo",@"Choose from library",nil,nil];    [photoSourcePicker showInVIEw:self.vIEw];   }- (voID)actionSheet:(UIActionSheet *)modalVIEw clickedbuttonAtIndex:(NSInteger)buttonIndex{    switch (buttonIndex)    {        case 0:        {            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {                UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];                imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;                imagePicker.delegate = self;                imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;                imagePicker.allowsEditing = YES;                [self presentVIEwController:imagePicker animated:YES completion:NulL];            }            else {                UIAlertVIEw *alert;                alert = [[UIAlertVIEw alloc] initWithTitle:@"Error"                                                    message:@"This device doesn't have a camera."                                                   delegate:self cancelbuttonTitle:@"Ok"                                          otherbuttonTitles:nil];                [alert show];                            }            break;        }                    case 1:        {            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotolibrary]) {                UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];                imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotolibrary;                imagePicker.delegate = self;                imagePicker.allowsEditing = YES;                [self presentVIEwController:imagePicker animated:YES completion:NulL];            }            else {                UIAlertVIEw *alert;                alert = [[UIAlertVIEw alloc] initWithTitle:@"Error"                                                    message:@"This device doesn't support photo librarIEs."                                                   delegate:self cancelbuttonTitle:@"Ok"                                          otherbuttonTitles:nil];                [alert show];                            }                        break;        }    }}- (voID) imagePickerController:(UIImagePickerController *)picker dIDFinishPickingMediawithInfo:(NSDictionary *)info{    [self dismissVIEwControllerAnimated:YES completion:NulL];    NSData *image = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalimage],0.1);    self.flUploadEngine = [[fileUploadEngine alloc] initWithHostname:@"http://www.atmeapp.com" customheaderFIElds:nil];    NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:                                        [MyClass str],@"email",nil];          self.flOperation = [self.flUploadEngine postDataToServer:postParams path:@"/addavatar.PHP" ];    [self.flOperation addData:UIImageJPEGRepresentation(image,0.5) forKey:@"userfile" mimeType:@"image/jpeg" filename:image];    [self.flOperation addCompletionHandler:^(MKNetworkOperation* operation) {        NSLog(@"%@",[operation responseString]);        /*               This is where you handle a successful 200 response        */    }         errorHandler:^(MKNetworkOperation *errorOp,NSError* error) {        NSLog(@"%@",error);        UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Error"                                                        message:[error localizedDescription]                                                       delegate:nil                                              cancelbuttonTitle:@"dismiss"                                              otherbuttonTitles:nil];        [alert show];            }];    [self.flUploadEngine enqueueOperation:self.flOperation ];  }@end

fileUploadEngine.h

////  fileUploadEngine.h//  fileUploader////  Created by Michael Roling on 5/7/12.//  copyright (c) 2012 NA. All rights reserved.//#import "MKNetworkEngine.h"@interface fileUploadEngine : MKNetworkEngine-(MKNetworkOperation *) postDataToServer:(NSMutableDictionary *)params path:(Nsstring *)path;@end

fileUploadEngine.m

////  fileUploadEngine.m//  fileUploader////  Created by Michael Roling on 5/7/12.//  copyright (c) 2012 NA. All rights reserved.//#import "fileUploadEngine.h"@implementation fileUploadEngine-(MKNetworkOperation *) postDataToServer:(NSMutableDictionary *)params path:(Nsstring *)path {    MKNetworkOperation *op = [self operationWithPath:path                                              params:params                                          httpMethod:@"POST"                                                 ssl:NO];    return op;     }@end

最后但并非最不重要的,我的PHP

$MysqLi = new MysqLi($host,$username,$password,$database);    if ($stmt = $MysqLi->prepare("UPDATE `user` SET imagepath=? WHERE email=?"))     {        $stmt->bind_param('ss',$albumname,$email);    $email = $_POST['email'];    $uploaddir = 'images/users/';    $file = basename($_fileS['userfile']['name']);    $uploadfile = $uploaddir . $file;    if (move_uploaded_file($_fileS['userfile']['tmp_name'],$uploadfile)) {    }    $albumname = $uploadfile;    $stmt->execute();        $stmt->close();         }    else {        printf("Prepared Statement Error: %s\n",$MysqLi->error);    }$MysqLi->close();

我没有在我的服务器上的PHP日志中得到任何错误,

解决方法 看起来基本上是正确的,我只是在PHP上做了MkNetworkKit /图像上传.我在这里发现的唯一错误就是这条线

[NSMutableDictionary dictionaryWithObjectsAndKeys:                                   @"email",[MyClass str]

你可能想要切换@“email”和[MyClass str],当使用dictionaryWithObjectsAndKeys时,值应该在key之前.

这是我的实现(在MKNetworkEngine的子类中):

-(MKNetworkOperation*) uploadImage:(UIImage*)image onSuccess:(EmptyBlock)successBlock onError:(MKNKErrorBlock)errorBlock {    NSMutableDictionary *params = [[NSDictionary dictionary]mutablecopy];    [params setValue:@"[YOUR_VALUE]" forKey:@"[YOUR_KEY]"];    MKNetworkOperation *op = [self operationWithPath:@"[YOUR_PATH]" params:params httpMethod:@"POST"];    [op addData:UIImageJPEGRepresentation(image,0.5) forKey:@"userfile" mimeType:@"image/jpeg" filename:@"[YOUR_filename]"];    [op onCompletion:^(MKNetworkOperation *completedOperation) {    if(successBlock) {        successBlock();    }    } onError:^(NSError *error) {        TFLog(@"RCNetworkEngine.uploadError:%@,error:%@",url,[error localizedDescription]);        if(errorBlock)            errorBlock(error);    }];    [self enqueueOperation:op];    return op;}
@H_301_2@ 总结

以上是内存溢出为你收集整理的ios – 使用MKNetworking图像上传PHP获取内部错误500全部内容,希望文章能够帮你解决ios – 使用MKNetworking图像上传PHP获取内部错误500所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1036088.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存