Php 将UIImage发布到web上
我刚开始从事xcode业务,到目前为止还不错,除了这个小细节:我不知道如何将UIImage发布到web上。在过去的3天里,我尝试了所有的事情(阅读和查询了很多),但都没有成功。答案,我想在我的眼皮底下,仍然。。。不走运 我把我写的代码留在这里(用objective-c和php编写):它根本不起作用!!没有上传图像。拜托,有人能帮我吗 //objective-CPhp 将UIImage发布到web上,php,objective-c,xcode,load,uiimage,Php,Objective C,Xcode,Load,Uiimage,我刚开始从事xcode业务,到目前为止还不错,除了这个小细节:我不知道如何将UIImage发布到web上。在过去的3天里,我尝试了所有的事情(阅读和查询了很多),但都没有成功。答案,我想在我的眼皮底下,仍然。。。不走运 我把我写的代码留在这里(用objective-c和php编写):它根本不起作用!!没有上传图像。拜托,有人能帮我吗 //objective-C NSData *theData = UIImagePNGRepresentation(photo.image); NSString
NSData *theData = UIImagePNGRepresentation(photo.image);
NSString *urlString = @"http://www.testes01.com/newsie/receberprofilephoto.php";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"file\"; filename=\"iphoneimage.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:theData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
//PHP
move_uploaded_file($_FILES["file"][tmp_name], "fotosprofile/" . $_FILES["file"]["name"]);
提前感谢。这是在web上上载图像的代码 self.image是我的uiimage对象,我制作了属性并合成了它。在self.image中获取您的图像,然后:-
NSData *imagedata=[NSData dataWithData:UIImagePNGRepresentation(self.image)];
NSString *base64string=[imagedata base64EncodedString];
NSString *str = [NSString stringWithFormat:@"http://www.testes01.com/newsie/receberprofilephoto.php"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:base64string forKey:@"imagedata"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusString %@",[request responseString]);
我希望这能帮助你 以下是在web上上载图像的代码 self.image是我的uiimage对象,我制作了属性并合成了它。在self.image中获取您的图像,然后:-
NSData *imagedata=[NSData dataWithData:UIImagePNGRepresentation(self.image)];
NSString *base64string=[imagedata base64EncodedString];
NSString *str = [NSString stringWithFormat:@"http://www.testes01.com/newsie/receberprofilephoto.php"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:base64string forKey:@"imagedata"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusString %@",[request responseString]);
我希望这能帮助你 你好@Jenifer,谢谢你的及时回复。不幸的是,我也尝试了ASIHTTPRequest库,但它也不起作用。然而,几小时前我注意到我发布图片的服务器不允许我以编程方式上传图片;我试过chmod 777,但没有得到允许。所以,我打电话给他们解决了我的问题。总之,代码是可以的。感谢您的回复,或许为了繁荣,代码就留在这里。请记住,如果代码不起作用,问题可能是您的文件夹或文件权限。再见!你好@Jenifer,谢谢你的及时回复。不幸的是,我也尝试了ASIHTTPRequest库,但它也不起作用。然而,几小时前我注意到我发布图片的服务器不允许我以编程方式上传图片;我试过chmod 777,但没有得到允许。所以,我打电话给他们解决了我的问题。总之,代码是可以的。感谢您的回复,或许为了繁荣,代码就留在这里。请记住,如果代码不起作用,问题可能是您的文件夹或文件权限。再见!这是可行的,唯一的错误是没有将文件夹修改为777以便您可以读写。这是可行的,唯一的错误是没有将文件夹修改为777以便您可以读写。