0

我知道有很多类似的问题,但我找不到适合我的问题。

我要做的是拍照或从相机胶卷中选择一张照片并将其上传到服务器并将该照片插入 mysql db。

NSURL *url = [[NSURL alloc] initWithString:@"myURL/whatever.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

NSData *imageData = UIImageJPEGRepresentation(image, 90);

[request addData:imageData withFileName:@"test.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
[request setCompletionBlock:^{
    NSString *responseString = [request responseString];
    if (responseString == nil) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title:rStrg" message:@"msg:rStrg" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
}];

[request setFailedBlock:^{
    NSError *error = [request error];
    NSLog(@"Error: %@", error.localizedDescription);
}];

[request startAsynchronous];

而php是

<? 
$photo = mysql_real_escape_string(file_get_contents($_FILES['image']['name']));

$conn = mysql_connect("localhost", "id", "password");

$dbconn = mysql_select_db("mydb", $conn) or die("Unable to find database");

mysql_query("set names utf8");

$Query = "INSERT INTO `my_table` ('sellerNum', 'Photo', 'Name', 'Tel', 'Location', 'Menu', 'Additional') VALUES (NULL, '$photo', NULL,NULL,NULL,NULL,NULL)";

$res = mysql_query($Query, $conn);
?>

什么都没有发生......

“照片”是长 BLOB,我想从 iOS 客户端插入“图像”,即 UIImage

我在代码中遗漏了什么吗?

4

0 回答 0