使用php在数据库中检索存储的图像

时间:2014-09-18 00:14:26

标签: php mysql image

我有存储在我的数据库中的图像我想在浏览器中加载它我有两页其中一页是

show_picture.php,另一个是get_image.php我的图片contents未在浏览器中加载,就像图片已被移动或其他东西但图片存储在数据库中所以这是我的代码

 <?php include("includes/student_session.php");?>
<?php confirm_logged_in();?>
<html>
<body>
<?php include("includes/connection.php");?>
<?php 
if (isset($_SESSION['exam_id']) and isset($_SESSION['register_id'])){

$exam_id=mysqli_real_escape_string($cnn,$_SESSION['exam_id']);

$query="select question_id from questions where exam_id={$exam_id} order by page_number asc";
$result=mysqli_query($cnn,$query);
if($result){

    while ($row=mysqli_fetch_array($result)){
    echo "<img src=\"get_image.php?id={$row['question_id']}\"/>";   
    }
}
}
?>
</body>
</html>

这是我的get_image.php

    <?php include("includes/connection.php");?>
<?php 
$question_id=$_REQUEST['id'];
$query="select question from questions where question_id={$question_id} limit 1";
$result=mysqli_query($cnn,$query);
 $row = mysqli_fetch_array($result);
  //mysql_close($cnn);

  header("Content-type: image/jpg");
  echo $row['question'];
?>

我想知道我错过了什么

0 个答案:

没有答案