2012-04-23 29 views
0

私がやっていることは次のとおりです。ユーザーが自分のiPhoneアプリケーションを使用して、写真と写真の2つの説明フィールドをMySQLにアップロードできるようにします。私はすでに2つの説明フィールドのテキストがアップロードされるように(PostURLと付属の.phpファイルをWebサーバー上で使用するように)アプリケーションを構成する方法を考え出しました。写真と写真の説明をアップロードする方法iphoneアプリで一緒に?

私が問題に遭遇しているのは、写真をミックスに追加し、写真とテキストフィールドをデータベースに対応する列(画像、名前、メッセージ)に一緒に送信する方法です。

私のヘッダーファイルと実装ファイルの外観はどうですか?追加ボーナスとして、私の.phpファイルはどのように見えますか?ここにそれらが現在存在する方法があり、FYIとして、これは写真ではなくテキストを送信するためにのみ動作します。

ヘッダファイル:

#import <UIKit/UIKit.h> 

#define kPostURL @"http://www.example.com/upload.php" 
#define kName @"name" 
#define kMessage @"message" 


@interface FirstViewController : UIViewController<UINavigationControllerDelegate,  UIImagePickerControllerDelegate>{ 

IBOutlet UITextField *nameText; 
IBOutlet UITextView *messageText; 
NSURLConnection *postConnection; 

UIImageView * theimageView; 
UIButton * choosePhoto; 
UIButton * takePhoto; 
} 

@property (nonatomic, retain) IBOutlet UITextField * nameText; 
@property (nonatomic, retain) IBOutlet UITextView * messageText; 
@property (nonatomic, retain) NSURLConnection * postConnection; 
@property (nonatomic, retain) IBOutlet UIImageView * theimageView; 
@property (nonatomic, retain) IBOutlet UIButton * choosePhoto; 
@property (nonatomic, retain) IBOutlet UIButton * takePhoto; 


-(IBAction) getPhoto:(id) sender; 



-(void) postMessage:(NSString*) message withName:(NSString *) name; 
-(IBAction)post:(id)sender; 



@end 

実装ファイル:

#import "FirstViewController.h" 

@implementation FirstViewController 
@synthesize nameText, messageText, postConnection, theimageView, choosePhoto, takePhoto,postData; 


- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 


-(void) postMessage:(NSString*) message withName:(NSString *) name { 


if (name != nil && message != nil){ 

    NSMutableString *postString = [NSMutableString stringWithString:kPostURL]; 

    [postString appendString:[NSString stringWithFormat:@"?%@=%@", kName, name]]; 

    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kMessage, message]]; 



    [postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]]; 
    [request setHTTPMethod:@"POST"]; 

    postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; 


} 

} 

-(IBAction)post:(id)sender{ 

[self postMessage:messageText.text withName:nameText.text]; 
[messageText resignFirstResponder]; 
messageText.text = nil; 
nameText.text = nil; 
[[NSNotificationCenter defaultCenter] postNotificationName:@"Test1" object:self]; 

} 

-(IBAction) getPhoto:(id) sender { 
UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 

if((UIButton *) sender == choosePhoto) { 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
} else { 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
} 

[self presentModalViewController:picker animated:YES]; 
} 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
[picker dismissModalViewControllerAnimated:YES]; 
theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
} 



- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
[super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
[super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
[super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 

答えて

0

(^ ^。)

"こんにちは申し訳ありませんが、誰かがように私の改訂を修正した場合、私の英語が良くないために、私はこれをいただければ幸いです"

こんにちは、(取得、ポスト、石鹸のようなWebサービス、jsonのような休憩サービス)リクエストを使用することができます。

私の経験から、画像を送信したい場合、base64binaryを使用する必要があります。これは、バイトの配列を送信することができなかったので、これはバイト配列の文字列表現ですが、 base64バイナリなしのnormal。

+0

残念ながら、これは私の質問には答えません。私は上記の私を修正する特定のコードを探しています。しかし、NTTakeの対応に感謝します。 – Mike

+0

Ok @Mike私は現在、受信データ用にバックエンドをPHPで作成する方法を教えていませんが、バックエンドをお持ちの場合は、iOSのフロントエンドをお手伝いします。がんばろう。 – NTTake

+0

私はPHPを理解することはできますが、フロントエンドファイルをコーディングする手助けはできますか?たとえば、ヘッダーファイルと実装ファイルの両方でコードをどのように表示するかを教えてください。 – Mike

関連する問題