【问题标题】:image from Database to a link in a tweet card (PHP)图片从数据库到推文卡中的链接 (PHP)
【发布时间】:2020-07-14 16:47:53
【问题描述】:

我正在尝试将图像从数据库插入到推特卡(链接),但推文中出现的链接没有图像

推文卡片示例(链接)

尝试为推特卡制作默认图片,效果很好

但是当我尝试从数据库中检索图像的名称并将其放入 <meta> 时,它在 twitter 中显示为空图像

也尝试回显$picture,路径显示为它在数据库中:/image.png

<head>
<?php

            //identify the user
    $un = $_SESSION['active_user'];

        //query to get that specific users information
        $query = "SELECT * FROM users WHERE username='$un'";

        //save the query in result variable
        $result = $db->prepare($query);

        //excecute the variable result
        $result->execute();

        //if the result has records in the database save the users info in the variables below
    if ($row = $result->fetch())
        {
            //validation variables
            $emptyFields = false;
            $error = false;
            $success = false;

            $n = $row['name'];
            $usn = $row['username'];
            $picture=$row['picture'];

        }

echo "<meta property='twitter:card' content='summary'>";
echo "<meta property='twitter:site' content=''>";
echo "<meta property='twitter:title' content=''>";
echo "<meta property='twitter:description' content=''>";
echo "<meta property='twitter:image' content='https://website.com/".$picture."'>";
echo "<meta name='twitter:creator' content='@abc'>";
echo "<meta name='twitter:text:title' content='website'>";

?>

我在这里缺少什么?是我检索数据的方式吗?请我尝试任何建议

【问题讨论】:

    标签: php html mysql twitter


    【解决方案1】:

    我不知道您如何将图像保存到该位置或数据库,但根据您的问题,

    阅读此内容,看看您是否遗漏了什么

    twitter:image 是代表页面内容的唯一图像的 URL。您应该使用通用图片,例如您的网站徽标、作者照片或其他跨多个页面的图片。此卡的图像支持 1:1 的纵横比,最小尺寸为 144x144 或最大为 4096x4096 像素。 图片的大小必须小于5MB。图像将在所有平台上裁剪为正方形。支持 JPG、PNG、WEBP 和 GIF 格式。仅使用动画 GIF 的第一帧。不支持 SVG。

    还有一件事,您似乎根据问题中的database : /image.png 将整个或部分图像目录保存在数据库中。请注意,这不是一个好的做法,因为您可能必须从网站的不同页面访问图像,即使这并非不可能,但也不值得,只需像 image.png 一样保存图像名称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2014-01-27
      • 2018-03-13
      相关资源
      最近更新 更多