facebook og:image does not fetch image from php file that echoes the URL

孤者浪人 提交于 2019-12-02 21:54:33

问题


facebook OG fetch image from echoed URL, is this possible?

since I included a php file that will echo the image URL but when I check in Sharing debugger the content is empty

<meta property="og:image" content="" />

my meta tag :

<meta property="og:image" content ="<?php include "meta_gambar.php"?>">

and the php file :

<?php
 $module=$_GET['module'];
 $id=$_GET['id'];
 if($module=='detailproduk'){
   //prepare query
   $stmt=mysqli_prepare($con,"SELECT gambar FROM produk WHERE id_produk=?");
    if($stmt===false){
       die("Prepare error" . htmlspecialchars($mysqli->error));
    }
    //Bind parameters
    $bp=mysqli_stmt_bind_param($stmt,"i",$id);
     if($bp===false){
        die("Binding error" . htmlspecialchars($stmt->error));
    }
     //Execute query
     $bp=mysqli_stmt_execute($stmt);
     if($bp===false){
         die("Execute error" . htmlspecialchars($stmt->error));
     }
     //bind result
     $bp=mysqli_stmt_bind_result($stmt,$gambar);
      if($bp===false){
          die("Result bind error" . htmlspecialchars($stmt->error));
      }
     //Fetch
      $bp=mysqli_stmt_fetch($stmt);
       if($bp===false){
           die("Fetching error" .htmlspecialchars($stmt->error));
      }
    $image = "http://images.rajafotocopy.com/foto_produk/$gambar";
   }else{
      $image = "http://images.rajafotocopy.com/raja.png";
 }
   echo"$image";
?>

Update

I just tried putting a direct URL image to the og:image content and it works

but including a php file that will echo the URL still results in blank


回答1:


Sounds like the current path is not where the include file is. Try specifying the full path to the include file, eg:

include $_SERVER['DOCUMENT_ROOT'] . "/path/to/meta_gambar.php";

Another option is to use require instead of include - if there is a problem with the file or path, require will generate an error and give you some ideas about what is wrong.



来源:https://stackoverflow.com/questions/41584379/facebook-ogimage-does-not-fetch-image-from-php-file-that-echoes-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!