上传和显示图像php mysqli

上传和显示图像php mysqli,php,image,mysqli,Php,Image,Mysqli,我需要关于显示图像的帮助,显示是正确的,但我不知道为什么图像没有出现 CREATE TABLE`images`( `id`int(11)不为空, `name`varchar(100)默认为空, `size`int(11)默认为空, `键入`varchar(20)默认为空, `content`mediumblob )ENGINE=MyISAM默认字符集=1; 这是我的“upload.php” 您必须在一段时间内提取['content']。像这样: $rs = mysqli_query($

我需要关于显示图像的帮助,显示是正确的,但我不知道为什么图像没有出现

CREATE TABLE`images`(
`id`int(11)不为空,
`name`varchar(100)默认为空,
`size`int(11)默认为空,
`键入`varchar(20)默认为空,
`content`mediumblob
)ENGINE=MyISAM默认字符集=1;
这是我的“upload.php


您必须在一段时间内提取['content']。像这样:

    $rs = mysqli_query($conn, $sql);
    while ( $imageData = mysqli_fetch_assoc($rs) ) {
        $content = $imageData['content'];
    }
    header("Content-type: $content ");
    echo $content;
我建议您检查并更改:

$sql = "SELECT type, content FROM images where id = {$imageId}"; 
为了


警报('已成功更新…');
window.location.href='index.php';

owh oke。下次我会试试的。因为我似乎用另一个脚本解决了它。但是谢谢你的帮助。虽然这段代码可以解决这个问题,但它如何以及为什么解决这个问题将真正有助于提高您的帖子质量,并可能导致更多的投票。请记住,你是在将来回答读者的问题,而不仅仅是现在提问的人。请在回答中添加解释,并说明适用的限制和假设。
$sql = "SELECT type, content FROM images where id = '$imageId' ";
    <?php
     error_reporting( ~E_NOTICE );
     require_once 'dbconfig.php';
 
     if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
      {
      $id = $_GET['edit_id'];
      $stmt_edit = $DB_con->prepare('SELECT userName, userProfession, userPic FROM 
        tbl_users 
         WHERE userID =:uid');
        $stmt_edit->execute(array(':uid'=>$id));
        $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
        extract($edit_row);
      }
      else
       {
      header("Location: index.php");
      }
 
      if(isset($_POST['btn_save_updates']))
     {
      $username = $_POST['user_name'];// user name
      $userjob = $_POST['user_job'];// user email
   
      $imgFile = $_FILES['user_image']['name'];
      $tmp_dir = $_FILES['user_image']['tmp_name'];
      $imgSize = $_FILES['user_image']['size'];
     
      if($imgFile)
       {
         $upload_dir = 'user_images/'; // upload directory 
         $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
         $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
         $userpic = rand(1000,1000000).".".$imgExt;
         if(in_array($imgExt, $valid_extensions))
         {   
          if($imgSize < 5000000)
         {
           unlink($upload_dir.$edit_row['userPic']);
          move_uploaded_file($tmp_dir,$upload_dir.$userpic);
       }
       else
       {
       $errMSG = "Sorry, your file is too large it should be less then 5MB";
      }
      }
      else
      {
      $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";  
      } 
     }
      else
      {
     // if no image selected the old image remain as it is.
     $userpic = $edit_row['userPic']; // old image from database
    } 
      
  
     // if no error occured, continue ....
     if(!isset($errMSG))
      {
        $stmt = $DB_con->prepare('UPDATE tbl_users 
              SET userName=:uname, 
               userProfession=:ujob, 
               userPic=:upic 
               WHERE userID=:uid');
              $stmt->bindParam(':uname',$username);
              $stmt->bindParam(':ujob',$userjob);
              $stmt->bindParam(':upic',$userpic);
              $stmt->bindParam(':uid',$id);
    
           if($stmt->execute()){
        ?>
                <script>
    alert('Successfully Updated ...');
    window.location.href='index.php';
    </script>
                <?php
   }
   else{
    $errMSG = "Sorry Data Could Not Updated !";
   }
  }    
 }
?>