mysql 存取 image/jpg

CREATE TABLE t_image (f_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f_image BLOB );
 

//put image to mysql

//http://192.168.0.10/picphp/1.php?pic=4.jpeg

<?php
  include("../catlib.php");
?>
<?PHP
  $user1='bunny';
  $password1='12341234';
  $database1='d_vegetable';
  $Picture=$_GET['pic'];
  if($Picture == ""){
    die("no _GET pic");
  }

  html_head();
  header1();
  no_cache();
  head_body();

  If($Picture != "none")   {
    $PSize = filesize($Picture);
    echo "size $PSize";br();
    $file_content=base64_encode(fread(fopen($Picture, "rb"), $PSize));
    $conn=mysqli_connect('localhost',$user1,$password1,$database1);
    if ($conn) {
      echo"ok1";br();
      $st1="INSERT INTO t_image VALUES(NULL,'$file_content')";
      if (mysqli_query($conn,$st1)){
        echo"ok2";br();
      } else {
        die("Can't Perform Query");
      }
    } else {
      echo "-1";     
    }
   } else { 
     echo"You did not upload any picture";
   }
  body_html_s();
?>

 

 

 

//get image form mysql

//http://192.168.0.10/picphp/2.php?pic_id=4

<?php
  include("../catlib.php");
?>
<?PHP
  $user1='bunny';
  $password1='12341234';
  $database1='d_vegetable';
  $pic_id=$_GET['pic_id'];

  if($pic_id == ""){
    die("no _GET pic_id");
  }

  $conn=mysqli_connect('localhost',$user1,$password1,$database1);
  if ($conn) {
    $st1="select f_image from t_image where f_id='$pic_id'";
    if ($picdata=mysqli_query($conn,$st1)){
      header("Content-Type:image/jpeg");
      echo base64_decode(mysqli_fetch_row($picdata)[0]);
    } else {
      die("Can't Perform Query");
    }
  } else {
    echo "-1";     
  }
?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值