2011-12-13 71 views
0

在我的应用程序中,我必须上传图片保存在我的iphone画廊到服务器使用PHP。如何找到保存在iPhone画廊中的图像的名称或路径?

我能够上传服务器上的图像以及上传时的日期和时间,但是我想在服务器上上传图像的名称。 请帮我一把。

以下在我的代码:

-(IBAction)upload:(id)sender 
{ 

NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"yyyyMMddHHmmss"]; 

    NSDate *now = [[NSDate alloc] init]; 

    NSString *imageName = [NSString stringWithFormat:@"Image_%@", [format stringFromDate:now]]; 

    [now release]; 
    [format release]; 

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:[NSURL URLWithString:@"http://url"]]; 
    [request setHTTPMethod:@"POST"]; 

    /* 
    Set Header and content type of your request. 
    */ 
    NSString *boundary = [NSString stringWithString:@"---------------------------Boundary Line---------------------------"]; 
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; 
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 

    /* 
    now lets create the body of the request. 
    */ 
    NSMutableData *body = [NSMutableData data]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];  
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", imageName] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(imageView.image, 90)]]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    //[body appendData:[[NSString stringWithFormat:@"geotag=%@&", [self _currentLocationMetadata]] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 

    // set body with request. 
    [request setHTTPBody:body]; 
    [request addValue:[NSString stringWithFormat:@"%d", [body length]] forHTTPHeaderField:@"Content-Length"]; 

    // now lets make the connection to the web 
    [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
    // 


} 
+0

过得好从照片库中的图像? – Harish

+0

是的harish先生..我能够浏览图片库的图像,我也能够上传图像以及....但我想上传图像的名称....... –

+0

harish先生... 。以及如何将多个图像从iphone上传到服务器 –

回答

0

在UIImagePickerControllerDelegate方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 
} 
相关问题