【发布时间】:2022-03-31 21:03:40
【问题描述】:
美好的一天。 因此,我正在努力将 blob 插入从表单发送的 mySQL 数据库中。无论如何,它在插入时失败,当我使用 var_dump 查看 $sql 变量时,我会收到此屏幕。 我的最后一点是将任何类型的文件插入数据库,无论大小。请注意,我正在尝试使用任何文件类型(zip、docx 或其他)来执行此操作。
这是我的表格
<form name="frmImage" enctype="multipart/form-data" action="upload.php"method="post" >
<label>Upload File:</label><br />
<input autocomplete="off" type="text" id="notes" style="width:50%" name="notes" placeholder="Write Something about this upload">
<input id="myfile" name="myfile" type="file"/>
<button style="width:20%" id="sendFile" name="sendFile" type="sendFile" value="sendFile">Submit</button>
</form>
这里是处理表单输入的 PHP 脚本。
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On'); //On or Off
session_start();
require_once('connect.php');
if (isset($_POST['sendFile'])) {
$imgData = ($_FILES['myfile']['tmp_name']);
$imageProperties = getimageSize($_FILES['myfile']['tmp_name']);
$notes = mysqli_real_escape_string($connection,$_POST['notes']);
$email = mysqli_real_escape_string($connection, $_SESSION['email']);
$comentity = mysqli_real_escape_string($connection,$_SESSION['entityname']);
$file_size = $_FILES['myfile']['size'];
$sql = "INSERT INTO `supportcontent` (`sentity`,`scontentdata`, `scontentnotes`, `suseremail`, `stype`,`ssize`)
VALUES('$comentity', '".file_get_contents($imgData)."','$notes','$email','{$imageProperties['mime']}','$file_size')";
var_dump($sql);
$current_id = mysqli_query($connection, $sql)
or die("<b>Error:</b> Problem on Image Insert<br/>" . mysqli_error($connection));
if (isset($current_id)) {
header("Location: landingpage.php?upload=success");
}
exit();
}
else{
echo 'pedestrian';
}
?>
所以我不确定出了什么问题,我知道问题正在我的插入中发生,但我不确定是什么原因造成的。
【问题讨论】:
-
base64_encode插入,base64_deconde读取 -
@SamSwift웃:您不会在 base64 中编码 BLOB。那将是无意义的,因为您将使用 base64 开销存储二进制文件。