将图像插入数据库

时间:2018-04-08 18:41:25

标签: php mysql image blob navicat

我正在尝试从数据库中获取图像,图像插入成功但在我获取时不显示。

这是我上传图片的代码

include("p1-connect.php");

if(isset($_POST['upload'])){


$file = $_FILES['picture'];

$fileName = $_FILES['picture']['name'];
$fileTmpName = $_FILES['picture']['tmp_name'];
$fileSize = $_FILES['picture']['size'];
 $fileError = $_FILES['picture']['error'];
 $fileType = $_FILES['picture']['type'];

 $fileExt = explode('.', $fileName);
 $fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg','jpeg','png'); //allowed file types 



 if(in_array($fileActualExt,$allowed)) 
{
    if($fileError === 0){
        if($fileSize < 1000000){

            $fileNameNew = uniqid('',true).".".$fileActualExt;
            $fileDestination = 'uploads/'.$fileNameNew;

            $query = "INSERT INTO image(image,image_name) VALUES('$fileName','$fileTmpName')";

            mysqli_query($connect,$query);
            $images = addslashes(file_get_contents($_FILES['picture']['tmp_name']));

            move_uploaded_file($fileTmpName, $fileDestination);

        }else{
            echo "Your file is too big";
        }

    } else{
        echo "An error uploading your files";
    }

} else{
    echo "You cannot upload files of this type";
}}

用于获取图像

<body>
 <form method="post" action="" enctype='multipart/form-data'>
 <input type='file' name='picture' />
 <input type='submit' value='Upload Image' name='upload'>
    <?php

        $sql = "SELECT * FROM image";

        $result =mysqli_query($connection,$sql);

        while($row = mysqli_fetch_array($result)){

            $imagee = $row['image'];}   
    ?>

    <tr>
   <td><img src="<?php echo $imagee; ?>" width="175" height="200"/></td>
    </tr>
</form></body>

仅显示损坏的图片图标

我的'图片'表包括:

id - int

image - blob

image_name - varchar

提前谢谢

0 个答案:

没有答案