【问题标题】:Upload,retrive and display image in HBase using Thrift and Php使用 Thrift 和 Php 在 HBase 中上传、检索和显示图像
【发布时间】:2013-03-20 21:33:16
【问题描述】:

我已经设置了 HBase 并尝试使用 Thrift-Php 上传图像然后显示它。我有一张表,其中包含一个名为 info 的列族,并使用了以下内容:

$tmpName=$_FILES["file"]["tmp_name"];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
try {
    $mutations = array(
         new Mutation( array(
            'column' => 'info:pic',
            'value' => $data
            ) ),
            );
$client->mutateRow( $t, $username, $mutations );
   } catch ( IOError $e ) {
        echo( "expected error: {$e->message}\n" );
   }

这似乎有效,因为它在 Hbase 中存储了一些东西,然后

$arr = $client->getRow($t, $username);
foreach ( $arr as $k=>$TRowResult  ) {
$values = $TRowResult->columns;
asort( $values );
foreach ( $values as $k=>$v ) {
        $usr= $v->value;
        $content=$_GET['username'];
    header('Content-type: image/jpg');
        echo $usr;
}

}

但我收到一条错误消息,指出图像包含错误。有人可以在 PHP 中提供一个例子吗? 谢谢。

【问题讨论】:

    标签: php image hbase thrift


    【解决方案1】:

    我认为,您的问题是您在存储数据时使用$data = addslashes($data);。将字符存储到 HBase 时无需引用字符。

    而且,您可以像这样检索数据:

    $values = $TRowResult->columns;
    $usr= $values['info:pic']->value;
    $content=$_GET['username'];
    header('Content-type: image/jpg');
    echo $usr;
    

    【讨论】:

      猜你喜欢
      • 2013-09-26
      • 2012-08-05
      • 1970-01-01
      • 2021-03-01
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 2015-06-13
      • 2017-07-18
      相关资源
      最近更新 更多