我正在尝试将图像上传到我的数据库。
这是表格。
<form action='index.php' method='POST' enctype='multipart/form-data'>
<label>Change Profile Pic</label> <br>
<input type='file' name='image'> <input type='submit' name=submitpicture
value='Upload'>
</form>
这是一组函数。
if(isset($_POST['submitpicture']))
{
$link = mysqli_connect('localhost','root','*****','*****');
$image = file_get_contents($_FILES['image']['tmp_name']);
$imagename = ($_FILES['image']['tmp_name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size== false)
{
echo "This is not an image.";
}
else
{
if(!$link) //This links to my database.
{
echo "No link";
}
else
{
$picturedatabase = "INSERT INTO databaseimage ('name','image') VALUES ('name','$image')";
if(mysqli_query($link,$picturedatabase));
{
echo "Entered into database";
}
}
}
}
当我上传图像时,我得到回显“已进入数据库”,但是当我检查数据库时没有任何行。我做错了什么?
最佳答案
相反,设置图像如下:
$image= 'data:image/' . $type . ';base64,' . base64_encode(file_get_contents($_FILES['image']['tmp_name']));
然后,当您将其作为图像源时,它将显示该图像。这也将减少请求。
关于php - 查询图像到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28567944/