dpz90118 2013-04-08 10:15
浏览 48

无法从数据库加载图像

I'm trying to load images stored in a database, but is not working. I only can see the links but, no images. I'm using longblob in the field where the pictures are stored.

JavaScript:

  <script>

    $(document).ready(function(){
         $.ajax({type: "POST",
                 url: "cargaImg.php",
                 success:function(data) {
                    $('#pinta').html(data);
                    }

         });  
    });
  </script> 

PHP

(images.php)

 <? require('conecta.php');
   $stmt=$oConni->prepare("SELECT PIC FROM FOTOS WHERE ID_PIC=?");
   $stmt->bind_param('i',$_GET['id']);
   $stmt->execute();
   $stmt->store_result();
   $stmt->bind_result($Foto);
   while ($stmt->fetch()) {
     header('Content-Type: image/jpeg');
     print $Foto;
   }
 ?>

(cargaImg.php)

    <?php
        require('conecta.php');
        ini_set('display_errors',1); error_reporting(E_ALL);  

        $cSQL="SELECT ID_PIC, PIC, NOMBRE FROM FOTOS";

        $stmt=$oConni->prepare($cSQL) or die($oConni->error);
        //$stmt->bind_param('i',$_POST['local']);
        $stmt->execute();                               
        $stmt->bind_result($id, $pic, $nombre);
        //$i=0;
        echo '<table cellspacing="0">';
        while ($stmt->fetch()) {

            if (!empty($pic)){ ?>
            <tr><td><img class="sifoto" src="images.php?id=<?=$id?>" width="60" height="60"  /></td></tr>
            <?}
            echo'<tr><td value="'.$id.'"><a target="_blank" href="'.$nombre.'">Enlace</a></td></tr>'; 
            //$i++;
        }   
        $stmt->close();
        echo'</table>';

     ?>
  • 写回答

1条回答 默认 最新

  • doudou348131346 2013-04-08 11:57
    关注

    SOLVED: i need this: $stmt->store_result();

        <?php
            require('conecta.php');
            ini_set('display_errors',1); error_reporting(E_ALL);  
            $cSQL="SELECT ID_PIC, PIC, NOMBRE FROM FOTOS";
            $stmt=$oConni->prepare($cSQL) or die($oConni->error);
            //$stmt->bind_param('i',$_POST['local']);
            $stmt->execute(); 
            $stmt->store_result();
            $stmt->bind_result($id, $pic, $nombre);
            //$i=0;
            echo '<table cellspacing="0">';
            while ($stmt->fetch()) {
    
                if (!empty($pic)){ 
                echo'<tr><td><img class="sifoto" src="images.php? id='.$id.'" width="100" height="100"  /></td></tr>';
                }
                echo'<tr><td value="'.$id.'"><a target="_blank" href="'.$nombre.'">Enlace</a></td></tr>'; 
                //$i++;
            }   
            $stmt->close();
            echo'</table>';
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?