Php 无法使用wpdb将图像插入数据库

Php 无法使用wpdb将图像插入数据库,php,mysql,blob,file-get-contents,Php,Mysql,Blob,File Get Contents,我试图运行此代码从前端获取图像输入。我知道我不能仅仅用这个$\u POST['img']上传图片。我读到我必须使用file\u get\u contents()。但我对这一点还不熟悉,我不知道如何确切地使用file\u get\u contents() 但是我尝试了这段代码,但插入失败 <form action="" method="post"> <label id="img">image: <input type="file" name="img" id='med

我试图运行此代码从前端获取图像输入。我知道我不能仅仅用这个
$\u POST['img']
上传图片。我读到我必须使用
file\u get\u contents()。但我对这一点还不熟悉,我不知道如何确切地使用file\u get\u contents()

但是我尝试了这段代码,但插入失败

<form action="" method="post">
<label id="img">image: <input type="file" name="img" id='media'/></label>
<input type="submit" name="Submit" value="upload"/>

<?php

global $wpdb;
if($_POST['Submit']) 
{
$image=$_POST['img'];

if($wpdb->insert(
    'image',
    array(

            'image' => $image


        )
) == false) echo 'Database Insertion failed';
else echo 'Database insertion successful<p />';
}
?>

图片:
这不起作用。在这之后,我尝试了这个。但仍然不成功

<form action="" method="post">
<label id="img">image: <input type="file" name="img" id='media'/></label>
<input type="submit" name="Submit" value="upload"/>

<?php

global $wpdb;
if($_POST['Submit']) 
{
$image=$_POST['img'];
$item = file_get_contents($_FILES['img']['tmp_name']);
if($wpdb->insert(
    'image',
    array(

            'image' => $item


        )
) == false) echo 'Database Insertion failed';
else echo 'Database insertion successful<p />';
}
?>

图片:
为此,我得到了一个警告
警告:file\u get\u contents():C:\xampp\htdocs\kite\wp content\plugins\php code widget\execphp.php(27):第11行的eval()d代码中的文件名不能为空

谁来帮帮我

在我的数据库中,表“image”中的列“image”具有数据类型BLOB,不确定问题是否出在这里


感谢您提前上传您应该添加的文件,
enctype=“multipart/form data”

然后使用

file_get_contents("new path")

伟大的那有帮助!我现在可以插入了!但是,当我在数据库中浏览我的图像并试图查看它时,我看到图像已损坏。我能看到图像的一部分,但不能看到全部。请对此提出建议。插入前的图像:插入后的图像截图:我知道了!问题是插入文件的最大大小是64kb,因此我的图像被破坏了。谢谢你的帮助。建议您是否知道如何增加插入文件的大小。我使用的是phpmyaddmin。yopu直接将图像存储在db??或者只有db中的图像名称??我直接存储图像
if (move_uploaded_file($_FILES['file']['tmp_name'], "your path". $_FILES["file"]['name'])) {
       // image will get uploaded here
}
file_get_contents("new path")