0

我在我的 Joomla 3.x 网站上使用 SobiPro,并且在我的条目中有一个自定义字段,它是一个图像,它存储在我的名为XXXX_sobipro_field_dataI have a 的表fid (field id)中,对于 Image 字段,它等于 23。但是每个条目的数据看起来像这样: jVFNT8JAEL37KzZ70kQp/US34WCgIEQ+AjUeyULXdgjtVrqgaPrf3d1WRA/E27438+a9maXEJZ8FcQiOqKDYp8SsMXuHF4XtGvcGj4HCnsK3EsOGjWnKsF8Qs0mway5gxRvrPNaMVXV0qWAhqC4gpmO2POuu5dj+ccIcPqqarPyw4SHXbE2N5ICKqqwgpTEz1jmrrGyC52wlgGdFj++ySJEtgjuT0SgYh9gv9RAJp09h0FU7OPVOiUg3qtuSad8gEkkbezZGCYM4Efqtqh7BD5pRkTwV3iX4WbUfCWk3KDp8w7d6GWV5mkBfFUhTSRU/C+7DyYygOLpRW6C92Wiiy10BWYwGwz4aToM+2nvW1TV63dENiANqo5Z7IXcpS22vT6DCOd/3KIyCLyHfcoNlYgsSu64Babz4/TFSK5JdutRa65xWt/1Ry1NL9A/fFf+jlD/AtxBDRvXFbe+c/FRafgE=
但是我需要显示图像,我应该如何处理这样的事情?

编辑

我这样做了:(它有效,但仅适用于 .png 图像)

<?php
$sid = $_GET["id"];
$db = mysql_connect("localhost", "admin", "root")
    or die("Impossible de se connecter : " . mysql_error());
mysql_select_db('database_name',$db); 

$sql = 'SELECT baseData, sid, fid FROM XXXX_sobipro_field_data WHERE sid = ' . $sid; 
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

while($data = mysql_fetch_assoc($req)) 
{ 
    if ($data["fid"] == 22) {
        $title = $data["baseData"];
    }
    if ($data["fid"] == 19) {
        $desc = $data["baseData"];
    }
    if ($data["fid"] == 17) {
        $activity = $data["baseData"];
    }
    if ($data["fid"] == 23) {
        $enc_image = $data["baseData"];
        $dec_image = unserialize(base64_decode($enc_image));
    }
}
?>
<p>
  <?php 
    echo "<span class=\"img\"><img src=\" ".$dec_image['original']." \" alt=\"\"> </img>  </span>";
  ?>
    <span class="title"><?php echo $title; ?></span>
    <br />
    <span class="activity"><?php echo $activity; ?></span>
    <br />
    <span class="desc"><?php echo $desc; ?></span>
</p>
<?php 
  mysql_close($db);
?>
4

3 回答 3

3

我也在寻找相同的答案......最终不得不自己弄清楚。

简而言之,您必须检查 2 个选项:

  1. 对于一些较短的字符串(被编码)只需使用 base64_decode($str)
  2. 对于更长的字符串,使用 gzinflate(base64_decode($str))

函数中的文件“/com_sobipro/lib/base/config.php”中提供了更长的版本:

public static function unserialize( $var, $name = null )
{
    $r = null;
    if ( is_string( $var ) && strlen( $var ) > 2 ) {
        if ( ( $var2 = base64_decode( $var, true ) ) ) {
            if ( function_exists( 'gzinflate' ) ) {
                if ( ( $r = @gzinflate( $var2 ) ) ) {
                    if ( !$r = @unserialize( $r ) ) {
                        throw new SPException( sprintf( 'Cannot unserialize compressed variable %s', $name ) );
                    }
                }
                else {
                    if ( !( $r = @unserialize( $var2 ) ) ) {
                        throw new SPException( sprintf( 'Cannot unserialize raw (?) encoded variable %s', $name ) );
                    }
                }
            }
            else {
                if ( !( $r = @unserialize( $var2 ) ) ) {
                    throw new SPException( sprintf( 'Cannot unserialize raw encoded variable %s', $name ) );
                }
            }
        }
        else {
            if ( !( $r = @unserialize( $var ) ) ) {
                throw new SPException( sprintf( 'Cannot unserialize raw variable %s', $name ) );
            }
        }
    }
    return $r;
}

以下是进行编码的函数:

public static function serialize( $var )
{
    if ( !( is_string( $var ) ) && ( is_array( $var ) && count( $var ) ) || is_object( $var ) ) {
        $var = serialize( $var );
    }
    if ( is_string( $var ) && function_exists( 'gzdeflate' ) && ( strlen( $var ) > 500 ) ) {
        $var = gzdeflate( $var, 9 );
    }
    if ( is_string( $var ) && strlen( $var ) > 2 ) {
        $var = base64_encode( $var );
    }
    return is_string( $var ) ? $var : null;
}

希望这可以帮助。

您解码的字符串如下所示:

a:5:{s:4:"数据";a:1:{s:4:"exif";a:3:{s:4:"文件";a:6:{s:8:"文件名";s:10:"51_ico.jpg";s:12:"FileDateTime";i:1417629743;s:8:"FileSize";i:1762;s:8:"FileType";i:2;s: 8:"MimeType";s:10:"image/jpeg";s:13:"SectionsFound";s:7:"COMMENT";}s:8:"COMPUTED";a:4:{s:4: "html";s:22:"width="63" height="63"";s:6:"高度";i:63;s:5:"宽度";i:63;s:7:" IsColor";i:1;}s:7:"COMMENT";a:1:{i:0;s:57:"CREATOR: gd-jpeg v1.0 (使用 IJG JPEG v62), quality = 75 "; }}}s:5:"image";s:40:"images/sobipro/entries/55/img_51_ico.jpg";s:5:"thumb";s:42:"images/sobipro/entries/55/ thumb_51_ico.jpg";s:3:"ico";s:40:"图像/sobipro/entries/55/ico_51_ico.jpg";s:8:"原始";s:36:"images/sobipro/entries/55/51_ico.jpg";}

于 2015-03-15T12:43:00.857 回答
0

修复了这个问题。

$entries[$key]['field_avatar'] = $entry->get('field_avatar');

// Encrypt Image
$enc_image = $entries[ $key ]['field_avatar'];

// Decrypt image 
**$dec_image = SPConfig::unserialize( $enc_image );**
于 2015-07-14T06:00:49.140 回答
0

将此用于图像类型字段数据:

    $img_data = unserialize(gzinflate(base64_decode( $sql_result)));

你会得到一个数组。

于 2022-01-13T13:47:20.520 回答