我无法在BLOB mysqli php中更新图像

时间:2014-11-02 10:13:15

标签: php mysqli

我无法在BLOB mysqli php中更新图片。

代码:

<?php


    // connect to the database
    include('connect-db.php');
    if (isset($_POST['submit']))
    {
    // confirm that the 'id' variable has been set
    if (isset($_GET['id']) && is_numeric($_GET['id']))
    {
        // get the 'id' variable from the URL
        $id = $_GET['id'];
$file=$_POST['image'];
$file = mysql_real_escape_string($file);

    if ($stmt = $mysqli->prepare("UPDATE studentdata SET image= ?
                        WHERE id=?"))
    {
        $stmt->bind_param("bi", $file, $id);
        $stmt->execute();
        $stmt->close();
    }
        else
        {
            echo "ERROR: could not prepare SQL statement.";
        }
        $mysqli->close();

        // redirect user after delete is successful
        header("Location: loginsuccess_student.php");
    }

}

?>

1 个答案:

答案 0 :(得分:0)

如果使用输入类型='文件'name ='image'(使用enctype =“multipart / form-data”表单)上传图像文件,请尝试以下操作:

$id = (int) $_GET[ "id" ];
$image = $_FILES[ "image" ][ "tmp_name" ];
$mysqli->query( "UPDATE `studentdata` SET `image` = LOAD_FILE( '$image' ) WHERE id = '$id' ");

如果图像文件只是一个链接(公共路径),根本不需要BLOB,VARCHAR(256)就足够了,您可以将文件输入源的示例用作:

$file = $_POST[ "image" ];