问题
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