上传图片ASIFormDataRequest

时间:2013-08-06 15:13:12

标签: ios xcode image upload asiformdatarequest

嗨我想从我的iPhone应用程序发送图像到我的服务器PHP,但我没有找到任何结果 iphone代码

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);
    }

php文件代码

<?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();

?>

谢谢你的帮助......

0 个答案:

没有答案