1

This code displays bunches of symbols rather than display the uploaded image

session_start();
include 'connection.php';
$id=$_SESSION["id"];

if (!isset($_SESSION['id'])) {
header("location:login.php"); 
}

?>

<?php

//DB Details
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPass = 'password';
$dbName = 'images';

//Create connection and select DB
$db = new mysqli ($dbHost, $dbUsername, $dbPass, $dbName);

Check DB connection

if ($db->connect_error) {
    die ("Connection Failed: " . $db->connect_error);
    }

//Get image data from database
$result = $db->query("SELECT image From images Where user_id=$id");

if ($result->num_rows > 0){
    $imgData = $result->fetch_assoc();

Here am Rendering the Image

    header("Content-type: image/jpeg");
    echo $imgData['image'];
}else{
    echo "Image not found...";
}
?>

When i try view the uploaded images it displays some bunch of symbols

cyberbest
  • 123
  • 1
  • 12
  • 1
    reason 74 for not storing images in the db –  Jan 09 '18 at 04:42
  • I think this may be a duplicate of [php-recreate-and-display-an-image-from-binary-data](https://stackoverflow.com/questions/2070603/php-recreate-and-display-an-image-from-binary-data) – Tom Drake Jan 09 '18 at 04:46

0 Answers0