drexlz0623 2016-01-19 22:31
浏览 26

无法在数据库中将已保存的图像显示为blob

Thank you for the help in advance.

I have a table called Noticia, which has 5 fields (id (int, autoincrement), titulo (varchar 200), noticia (Text 1000), foto (blob) and aphototype(varchar50))

In this case I'm able to save data to the Table using the code

<?php require_once('connectiononly.php'); ?>
<?php

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")){

$titulo = $_POST['titulo'];
$noticia = $_POST['noticia'];
$foto = addslashes (file_get_contents($_FILES['foto']['tmp_name']));
$image = getimagesize($_FILES['foto']['tmp_name']);//to know about image type etc

$imgtype = $image['mime'];

$q ="INSERT INTO noticia VALUES('','$titulo','$noticia','$foto','$imgtype')";

mysql_select_db($database_TRS, $TRS);
  $r = mysql_query($q, $TRS) or die(mysql_error());
}

mysql_select_db($database_TRS, $TRS);
$id = $_GET['id'];
$querytype = "SELECT foto,aphototype FROM noticia where id='$id'";
$type = mysql_query($querytype, $TRS) or die(mysql_error());

mysql_select_db($database_TRS, $TRS);
$query_show = "SELECT * FROM noticia";
$show = mysql_query($query_show, $TRS) or die(mysql_error());
$row_show = mysql_fetch_assoc($show);
$totalRows_show = mysql_num_rows($show);

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title> Creacion de Noticia</title>
    <meta charset="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="Estilos.css"/>
    <style>
    table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
    }
    th, td {
        padding: 5px;
}
</style>
</head>
<body>
<div class="contenedor">
    <body>
<header>
            <div id="subheader">
                <div id="logotipo"> <p><img class="thumb1" src="alianzafc.jpg" alt="thumbail #2" />
</p>

</div>
</div>
</div>
        </header>
<section id="contenido">
                            <article>
                                <hgroup><h2 class="Titulo1" align="center">Crear nueva Noticia</h2></hgroup>
</br>

<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>" method="POST">

<table border=0 align=center>
<td>Titulo de la Noticia</td><td><input type=text name="titulo"></td>
</tr>
<tr>
<td>Contenido de la Noticia</td><td><input type=text name="noticia"></td>
</tr>
<tr>
<td>Foto de la Noticia</td><td><input type=file name="foto"></td>
</tr>
<tr>
<td></td><td><input type=submit name="submit" value="Guardar Noticia"></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<div align="center">
  <table width="561" border="5" bgcolor="#0033FF" >
    <tr>
      <th width="189" scope="col"><font color="white">Titulo:</font></th>
      <th width="192" scope="col"><font color="white">Contenido:</font></th>
      <th width="192" scope="col"><font color="white">Foto:</font></th>
     <th width="73" scope="col"><font color="white">Borrar</font></th>
      </tr>
      <?php  while ($row_show = mysql_fetch_assoc($show)); ?>
      <tr bgcolor="#FFFFFF">
      <th scope="col" ><?php echo $row_show['titulo']; ?></th>
      <th scope="col" ><?php echo $row_show['noticia']; ?></th>
      <th scope="col" ><?php $type = "Content-type: ".$row['aphototype']; header($type); echo "<img src= $querytype?id=".$row_show['id']." width=300 height=100/>";?></th>
       <th scope="col" ><a href="#"><img src="eliminar.png" alt="Delete" width="16" height="16" /></a></th>
          </tr>

    <tr>
      <th colspan="4" scope="col" >

      </th>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
<p>&nbsp;</p>
</body>
</html>

<?php
mysql_free_result($show);

mysql_free_result($type);

?>

The problem is at the point of displaying the data which doesn't work

<p>&nbsp;</p>
    <div align="center">
      <table width="561" border="5" bgcolor="#0033FF" >
        <tr>
          <th width="189" scope="col"><font color="white">Titulo:</font></th>
          <th width="192" scope="col"><font color="white">Contenido:</font></th>
          <th width="192" scope="col"><font color="white">Foto:</font></th>
         <th width="73" scope="col"><font color="white">Borrar</font></th>
          </tr>
          <?php  while ($row_show = mysql_fetch_assoc($show)); ?>
          <tr bgcolor="#FFFFFF">
          <th scope="col" ><?php echo $row_show['titulo']; ?></th>
          <th scope="col" ><?php echo $row_show['noticia']; ?></th>
          <th scope="col" ><?php $type = "Content-type: ".$row['aphototype']; header($type); echo "<img src= $querytype?id=".$row_show['id']." width=300 height=100/>";?></th>
           <th scope="col" ><a href="#"><img src="eliminar.png" alt="Delete" width="16" height="16" /></a></th>
              </tr>

        <tr>
          <th colspan="4" scope="col" >

          </th>
        </tr>
      </table>

Any Ideas what I'm doing Wrong and how to fix it?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP