以下是我的代码文件...
我无法插入图像。错误为,未定义变量:image

<html>
    <head>
        <title> Upload an image </title>
    </head>
    <body>
        <form action="image-disp.php" method="post" enctype="multipart/form-data">
            File:
            <input type="file" name="image" value=iamge><br>
            <input type="submit" value="Upload">
        </form>
        <?php
        mysql_connect("localhost", "root", " ") or die(mysql_error());
        mysql_select_db("mysql") or die(mysql_error());
        echo "connected";
        if (!isset($_FILES['image'] ['tmp_name'])) {
            echo "Choose an image";
        } else {
            echo $image = addslashes($_FILES['image'] ['tmp_name']);
            echo $image_name = addslashes($_FILES['image']['name']);
            echo $image_size = getimagesize($_FILES['image'] ['tmp_name']);
        }
        if ($image_size = FALSE) {
            echo "It's not an image";
        } else {
            $result = "INSERT INTO testblob (image_id, image, image_size) "
                    . "VALUES (' ' ,'$image', '$image_size')";
        }
        echo "inserted";
        ?>
    </body>
</html>

最佳答案

最好只将图像名称保存在数据库中,并将文件保存在某个文件夹中

$result = "INSERT INTO testblob ( image, image_size)
                         VALUES ('$image_name', '$image_size')";


然后您像这样检索它:

<img src="path/<?php echo $row['image_name'];?>">

09-25 19:59