0

I can get a BLOB image from my MySQL database but I want to show it as a preview image when I post to facebook. I don't want to save the image to my computer because I will end up with too many images. The closest I can get is showing a load of ascii code instead of the actual image. Is it even possible to achieve this? This is the code I have at the moment.

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/config.php");
$keys = htmlspecialchars($_GET['id']);
$query = "SELECT * FROM birdtabletop WHERE id='$keys' AND approvalMsg = 'Approved' LIMIT 1";
if(!isset($error)){ 
    try {
        foreach ($db->query($query) as $row) {
            //set vars here
            $tTitle = $row['tabletop_name'];
            $tPicture = $row['tabletop_photo'];
        }
    } catch(PDOException $e) {
        header('Location: login.php');
    }
}
if(!isset($row)){
    header('Location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">

<head>
   <?php include_once("includes/analyticstracking.php") ?>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><?php echo $tTitle; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="description" content="">
    <meta property="og:title" content="<?php echo $tTitle; ?>">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://www.finchkeeper.com/viewtabletop.php<?php echo "
        ?id=".htmlspecialchars(filter_input(INPUT_GET, 'id')); ?>">
<?php
            if($tPicture != NULL){
                echo '<meta property="og:image" content="data:image/jpeg;base64,'.base64_encode( $tPicture ).'"/>';
            }else{
                echo '<meta property="og:image" content="https://www.finchkeeper.com/images/tabletop.jpg">';
            }
?>
    <meta property="og:description" content="" />
TylerH
  • 20,799
  • 66
  • 75
  • 101
Dion
  • 127
  • 1
  • 1
  • 9
  • 1
    Your `filter_input` calls are useless, you need to tell it what you want filtered. Per manual "If omitted, FILTER_DEFAULT will be used, which is equivalent to FILTER_UNSAFE_RAW. This will result in no filtering taking place by default." I think https://stackoverflow.com/questions/18460421/pass-base64-jpeg-image-to-ogimage might be what you are after – user3783243 Aug 24 '22 at 14:55
  • fixed now, thanks. hope I can get an answer to my origional question now :) – Dion Aug 24 '22 at 15:05
  • The link should be for the original question, that doesn't work? – user3783243 Aug 24 '22 at 15:10
  • I don't understand what you mean? – Dion Aug 24 '22 at 15:14
  • There is a link at the end of the first comment. Did you click that? – user3783243 Aug 24 '22 at 15:15
  • user3783243 yes, I tried that already but I still just get a load of ascii code echo'd out – Dion Aug 24 '22 at 15:16

0 Answers0