I want to upload images in server using ASIHTTPRequest library in my IPhone app.
For image upload, i am using ASIFormDataRequest to upload into server.
I have tried the below codes in my app but it couldn't working and image didn't uploaded in server.
NSURL *url = [NSURL URLWithString:@"http://www.anglerdemo.com/Appln/Aghaven_iphone/Uploadphoto.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.requestMethod = @"POST";
NSString *fileName = @"iphone.jpg";
[request addPostValue:fileName forKey:@"name"];
// Upload an image
UIImage *img = [UIImage imageNamed:fileName];
NSData *imageData = UIImageJPEGRepresentation(img, 90);
NSLog(@"imageData ==> %@", imageData);
[request setData:imageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"image"];
[request setDelegate:self];
[request startAsynchronous];
I have tried above codes in my app, request successfully executed and i got the alert message in "requestFinished" delegate method of ASIHTTPRequest. but image didn't uploaded in server.
- (void)requestFinished:(ASIHTTPRequest *)request
{
[[[[UIAlertView alloc]
initWithTitle:@"Message"
message:@"Success!!!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]
autorelease]
show];
NSLog(@"success ==> ");
}
I have tried php file script for upload is below.
<?php
$uploaddir = 'upload_files/';
$file = basename($_FILES['image']['name']);
$uploadfile = $uploaddir . $file;
if(move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile))
{
echo "Photo has been saved successfully!…;
}
else {
echo "Failed";
}
?>
Please help in this regards.
Thanks!!!