开发者

could not display image

开发者 https://www.devze.com 2023-01-04 16:36 出处:网络
When i\'m trying to display the image from the database the image is not been displayed didn\'t know what was the problem,here is my code.

When i'm trying to display the image from the database the image is not been displayed didn't know what was the problem,here is my code.

show_desc.php

<?php 
  $errmsg = "";

  if (! @mysql_connect("localhost","root","")) {
    $errmsg = "Cannot connect to database";
  }

  @mysql_select_db("dbname");

  if (isset($_GET['img_name'])) {
    $gotten = @mysql_query("select img from image where img_id = ".$_GET['img_name']);

    header("Content-type: image/x-ms-bmp");

    while ($row = mysql_fetch_array($gotten)) {
      print $row['img'];
    }
    mysql_free_result($gotten);
  }
  ?>

display.php

  <?php
    $errmsg = "";

    if (! @mysql_connect("localhost","root","")) {
      $errmsg = "Cannot connect to database";
    }

    @mysql_select_db("dbase_mgb");

    $strSQL = "select * from image";
    $rsPix = mysql_query($strSQL);
    $numRows = mysql_numrows($rsPix);

    $i = 0;

    while($i < $numRows) {
  ?>

  <image src="show_desc.php?img_id=<?php echo mysql_result($rsPix,$i,"img_id"); ?>"开发者_运维问答

  <?php

    $i++;

    }
  ?>

can anyone please help me with this?


  1. Your display.php doesn't seem to produce proper <img> tags.
  2. Check that your img field in the database is marked as BINARY


i thing you use image data type as BLOB


Why are you strong images into the database? It is better idea to simply save the name/path of the images into the database, upload them to a folder and show them while retrieving their name in <img> tags.

0

精彩评论

暂无评论...
验证码 换一张
取 消