美好的一天。 所以我正在努力将一个 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 函数:Error in SQL syntax when trying to upload image to BLOB field
关于php - 如何使用 PHP 上传任何文件类型的 BLOB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51082543/