0

在我的 PHP 中,我想发送一个包含数据库数据的数组。所有值都应该作为 NSString 被接受,除了一个在数据库中存储为“中等 blob”的图像,我正在尝试传递它的 NSData\UIImage 值。

while ($row = mysql_fetch_array($result)) {

    $add = array(); 
    $add["Id"] = $row["Id"]; 
    $add["Mail"] = $row["Mail"];
    $add["Category"] = $row["Category"]; 
    $add["Phone"] = $row["Phone"]; 
    $add["Msgs"] = $row["Msgs"];
    //image from blob
    $add["Picture"] = $row["Picture"];

    // push single add into final response array 
    array_push($response["adds"], $add); 
} 
// success 
$response["success"] = 1; 
$response["message"] = "Adds loaded successfully";
// echoing JSON response 
echo json_encode($response); 

现在在 Xcode 中,除了为 NULL 的图像之外,所有值都可以正常接收。我尝试在 PHP 中使用 base64 对其进行编码并在 Objective-C 中进行解码,但 xcode 崩溃了,因为它仍然为 NULL。我试图定义:

header("Content-type: image/png");

或者

file_put_contents("image.png", $add["Picture"]);

但它总是作为 NULL 接收。没有存储 blob 的行返回为 ' ',只有具有内容的行返回 NULL。我是 PHP 新手,我确信我犯了一些基本的愚​​蠢错误。

顺便说一句,我的 Objective-C 代码是:

const void *bytes = [[addPicture objectAtIndex:indexPath.row] bytes];
int length = [[addPicture objectAtIndex:indexPath.row] length];
NSData* imageData = [[NSData alloc] initWithBytes:bytes length:length];
aCell.cellBackImg.image = [UIImage imageWithData:imageData];
4

0 回答 0