Upload image to mySQL via php and AFNetworking from iOS -


i have been looking everywhere online way upload image ios app via php using afnetworking 2.0 mysql database. have found solution after searching , searching. can take picture , upload database. when download image saves "locations-29.image" or "locations-30.image" don't why file extension .image? when image saves database shows this: /var/lib/php/session/phpa7ffdb

i appreciate help. xcode? question how can save .jpeg/png file rather i'm getting now? , okay url /var/lib/php/session/phpa7ffdb ?

here code:

- (ibaction)postimagetoserver:(uibutton*)sender {  cgfloat compression = 1.0f; uiimage *image = _uploadimage.image;  nsdata *imagedata1 = uiimagejpegrepresentation(image, compression);    int random = arc4random() % 9999999; nsstring *photoname=[nsstring stringwithformat:@"%d-image.jpg",random];  afhttprequestoperationmanager *manager = [[afhttprequestoperationmanager alloc]     initwithbaseurl:[nsurl urlwithstring:@"http://urlhere.com"]]; manager.responseserializer = [afhttpresponseserializer serializer]; nsdictionary *parameters = @{@"filename": photoname}; afhttprequestoperation *op = [manager post:@"getimage.php?" parameters:parameters     constructingbodywithblock:^(id<afmultipartformdata> formdata) {     [formdata appendpartwithfiledata:imagedata1 name:@".jpg" filename:photoname     mimetype:@"image/jpeg"]; } success:^(afhttprequestoperation *operation, id responseobject) {     nslog(@"success: %@ ***** %@", operation.responsestring, responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) {     nslog(@"error: %@ ***** %@", operation.responsestring, error); }]; [op start]; } 

this php file:

<?php $hostusername = ""; $hostpassword = ""; $hostname = "";   $name = $_post['name']; $image1 = basename($_files['image']['tmp_name']); $tmp_img = $_files['image']['tmp_name'];  $dbhandle = mysql_connect($hostname, $hostusername, $hostpassword)   or die("unable connect mysql");  $selected = mysql_select_db("em",$dbhandle)  or die("could not select username");  $query = mysql_query("insert locations (name, image)         values ('$name','$tmp_img')");  mysql_close($dbhandle); ?> 


Comments