我有一个php文件,该文件可加载图像并接收文本,然后将其发送到另一个.php,后者运行查询以将数据保存在数据库中...在我的本地版本中一切正常,但在该版本中Web仅保存文本,而longblob不保存。
我尝试使用$ _FILES ['error'],mysqli_sql_exception,error_reporting等进行调试,但是没有警告或错误出现。
我知道也有类似的帖子,我检查了它们,但没有一个对我有帮助
本地和服务器中php的版本均为7.3,两者的mysql属性max_allowed_packet均为20M。
这发送数据:
<form enctype="multipart/form-data" method="post" action="php/saveImage.php" enctype="multipart/form-data">
<div class="form-group">
<label for="classification" class="control-label">classification</label>
<input type="text" class="form-control" id="classification" placeholder="..." maxlength="50" name="classification" required>
</div>
<div class="form-group">
<label for="image" class="control-label">Image</label>
<input type="file" id="imagen" name="imagen" accept=image/*>
</div>
<input type="submit" class="btn btn-primary" value="Save">
</form>
这将获取并保存数据:
<?php
session_start();
include 'Connection.php';
$connection = new Connection();
$conn = $connection-> getConnection();
$classification = $_POST['classification'];
$blob = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$sql = "INSERT INTO gallery (image, title) VALUES ('$blob', '$classification')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "Success";
} else {
echo "Error";
}
?>
更新:我知道该代码具有安全漏洞和不良做法,但现在不是重点,仅供个人使用。
答案 0 :(得分:-1)
最后,我找到了解决方案,问题是数据库中的数据类型是blob而不是longblob,通过这种更改,它可以正常工作,不用了!