upload image ASIFormDataRequest

484 Views Asked by At

hi i want to send image to my server php from my iphone app but i found no results the iphone code

NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpeg"];
   NSURL * url = [NSURL URLWithString:@"http://www.myserver.com/uploadimages.php"];
    ASIFormDataRequest *request =
    [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
    [request setDelegate:self];
    [request setPostValue:@"photo.jpeg" forKey:@"name"];
    [request setFile:fileLocation forKey:@"photo"];
    [request startSynchronous ];
    NSError *error = [request error];
    if (!error)
    {
        NSString *response = [request responseString];
        NSLog(@"response:%@",response);
    }

the php files code

<?php
$img = $_POST['photo'];
    //connect to the db  
$user = '*******';  
$pswd = '*******';  
$conn = mysql_connect('mysql51-79.perso', $user, $pswd);  
mysql_select_db('*******'); 

$query = "INSERT INTO photos  VALUES ('','$img')";
mysql_query($query) or die(mysql_error());
echo "Image id is ".mysql_insert_id();

?>

thank you for your help....

0

There are 0 best solutions below