使用php无法将blob透明图像转换为json

时间:2014-01-04 07:02:59

标签: php json sqlite blob

if (function_exists($_GET['displayResult']))
    displayResult();

function displayResult() {
    $db = new PDO('sqlite:ROS.sqlite');
    $sql = 'select * from Item_Image_Large';
    $result = $db->query($sql);
    $rows[] = array();
    while ($row = $result->fetchObject()) {
        $rows['Item_Image_Large'][] = $row;
        foreach ($rows as $key => $value) {
            $newArrData[$key] = $rows[$key];
            $newArrData[$key]['image_large'] = base64_encode($rows[$key]['image_large']);
        }
    }

    header('Content-type: image/png');
    $result2 = json_encode($newArrData);
    echo $result2;
}

此代码用于从数据库获取BLOB数据并尝试将其转换为JSON格式,但它不起作用。 BLOB数据采用PNG格式。

1 个答案:

答案 0 :(得分:0)

更改

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

header('Content-Type: application/json');