gpt4 book ai didi

php - 使用 php 将图像插入 mysql 不起作用

转载 作者:行者123 更新时间:2023-11-29 21:09:40 25 4
gpt4 key购买 nike

我有一个网站,可以将名称、日期、消息和IMG等信息插入mysqli数据库这是我的代码

HTML 和 PHP 代码

<form action='' method='POST'>
<input type='date' name='bdate' min='2003-12-31' max='2016-04-02'><br><br>
<input type='text' name='send_name'/>
<input type='text' name='min_name' value='Some Name' disabled='true' ><br>
<textarea name='my_text' rows='11' cols='40'></textarea>
<input type='submit' name='submit' value='Send'>
<input type='file' name='Image' id='Image' >
</form>

if (isset($_POST['submit'])) {
$imgData = $_FILES['Image']['tmp_name'];
$imageProperties = $_FILES['Image']['tmp_name'];
$sql = "INSERT INTO output_images(imageType ,imageData)
VALUES('".$imageProperties['mime']."', '".$imgData."')";
$current_id = mysqli_query($connection,$sql) or die("<b>Error:</b> Problem on Image Insert<br/>" . mysqli_error());
if(isset($current_id)) {
echo "Image Upload Ok";
}
$imgData = $_FILES['Image']['tmp_name'];
$imageProperties = $_FILES['Image']['tmp_name'];
$min_name = "Ministry Of Intinor";
$dat = $_POST['bdate'];
$info = $_POST['my_text'];
$mySQL = mysqli_query($connection," INSERT INTO `mddb`.`ministry_tbl` (`sender_name`, `min_name`, `b_date`, `infos`,`img`,`img_name`) VALUES ('".$_SESSION['username']."', '".$min_name."', '".$dat."', '".$info."','".$imgData."','".$imageProperties['mime']."') ");
if ($mySQL) {
echo "Done";
}
}

我的问题是数据库不存储BLOB* img并且它总是[BLOB - 0 B]

注意 enter image description here

最佳答案

you have to use enctype="multipart/form-data" add input type="file" before submit button

            <input type='date' name='bdate' min='2003-12-31' max='2016-04-02'><br><br>

<input type='text' name='send_name'/>
<input type='text' name='min_name' value='Some Name' disabled='true' ><br>
<textarea name='my_text' rows='11' cols='40'>
<input type='file' name='Image' id='Image' >
<input type='submit' name='submit' value='Send'>


</form>

关于php - 使用 php 将图像插入 mysql 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36497397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com