doue9730 2017-03-28 07:43 采纳率: 100%
浏览 34

从数据库显示的图像损坏

Hi guys and thanks so much for any help you can give. here in this code in uploading the img to a mysql data base using a form, this the code to upload the photos to the data base.

database

CREATE TABLE `user_pic` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `img` LONGBLOB NOT NULL,
    `img_name` VARCHAR(200) NOT NULL,
    `upload_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `user_id` INT(11) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB

upload_img.php

  require ('functions.php');
  if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $conexion = db_cnt('user_login', 'root', '');
    if (!$conexion) {
      die('Could not connect: ' . mysql_error());
    }


    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];

      // Read the file
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);

      // Create the query and insert
      // into our database.
      $statement = $conexion->prepare("INSERT INTO user_pic (img) VALUES ('$data')");
      $statement->execute(array(
            ':img' => $data
        ));
    }
    else {
      print "No image selected/uploaded";
    }
  }

An here i loop all the images and display the images on the html

gallery.php

<?php
  require ('../include/upload_img.php');

  $conexion = db_cnt('user_login', 'root', '');
  $statement = $conexion->prepare("SELECT * FROM user_pic");
  $statement->execute();
  $fotos = $statement->fetchAll();

?>
            <?php foreach($fotos as $foto):?>
            <div class="col-xs-12 col-sm-4 col-md-3 item-photo">
              <div class="photo">
                <img class="img-responsive" src="<?php echo $foto['img'] ?>" alt="">
                <a class="search zoom fancybox" href="../img/992.jpg"><span class="icon-search"></span></a>
                <a class="star" href="#"><span class="icon-star"></span></a>
                <a class="download" href="#"><span class="icon-download"></span></a>
              </div>
            </div>
            <?php endforeach;?>

but the problem is that only show me broken images and i don´t have any idea what could the problem, if you could give some help that will be nice, thanks so much guys for your time.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab