Привет всем мне нужна помощь. Я могу сделать это? Я работаю над новым скриптом с этой конфигурацией PHP.
<?php
function random_pic($dir, $nf=3)
{
$files = glob($dir . DIRECTORY_SEPARATOR . '*.jpg');
shuffle($files);
return array_pop($files);
}
//$number = rand(); ?v=$number
$path = 'images';
$file_images = random_pic($path, 1);
$image = file_get_contents($file_images);
$og_img = base64_encode($image);
?>
<meta charset = "utf-8">
<meta http-equiv = "X-UA-Compatible" content = "IE=edge">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<meta property = "og:title" content = "<?php echo basename($file_images)?>" />
<meta property = "og:type" content = "article" />
<meta property = "og:url" content = "http://YourDomain.com" />
<meta property = "og:image" content = "http://YourDomain.com/<?php echo $file_images ?>" />
конфигурация эха изменяет файл изображения при каждой перезагрузке в og:image и og:title, автоматически изменяет заголовок с именем изображения, которое будет отображаться в og:image
у меня все работает, но изображение, которое будет отображаться на og:image, показывает тип изображения в заголовке, например, love.jpg
такое шоу
<meta property = "og:title" content = "Love.jpg" />
<meta property = "og:type" content = "article" />
<meta property = "og:url" content = "http://yourdomain.com" />
<meta property = "og:image" content = "http://yourdomain.com/images/Love.jpg"/>
<meta property = "og:description" content = "Liked it? Click Here for More."/>
<meta property = "og:site_name" content = "yourdomain.com - Love Test?"/>
вопрос в том, как скрыть тип jpg в заголовке изображения
<meta property = "og:title" content = "Love.jpg" />
заранее спасибо






Вы можете попробовать следующее, используя pathinfo:
<?php
function random_pic($dir, $nf=3) {
$files = glob($dir . DIRECTORY_SEPARATOR . '*.jpg');
shuffle($files);
return array_pop($files);
}
$path = 'images';
$file_images = random_pic($path, 1);
$fileinfo = pathinfo($file_images);
$image = file_get_contents($file_images);
$og_img = base64_encode($image);
?>
<meta charset = "utf-8">
<meta http-equiv = "X-UA-Compatible" content = "IE=edge">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<meta property = "og:title" content = "<?= $fileinfo['filename'] ?>" />
<meta property = "og:type" content = "article" />
<meta property = "og:url" content = "http://YourDomain.com" />
<meta property = "og:image" content = "http://YourDomain.com/<?= $file_images ?>" />
@gratienasimbahwe - надеюсь, он использует более позднюю версию. PHP 5.2 очень стар и больше не должен использоваться.
Да, но мы никогда не знаем, некоторые новички просто используют 5.1 на локальном хосте.
если версия PHP >=PHP 5.2.0