0
我试图上传图像到mysql数据库,但是当我上传图像时,我收到确认消息,但是当我检查我的数据库图像行是空的,我做错了什么?插入图像到数据库
<?php include "connection.php"; ?>
<?php
$n=$_POST["num"];
$t=$_POST["texto"];
$i=$_POST["imagem"];
$image = addslashes(file_get_contents($_FILE['$i']['tmp_name']));
if ($connect->connect_error){
\t die("Connection failed: " . $connect->connect_error);
}
$sql = "UPDATE servicos SET texto='$t', imagem='{$image}' where nmr=$n" ;
if ($connect->query($sql) === TRUE) {
\t echo "informação atualizada";
} else {
\t echo "Error: " . $sql . "<br>" . $connect->error;
}
$connect->close();
?>
<html>
<body>
<div class="formulario" style="width: 100%; height: 100%;">
<form enctype="multipart/form-data" name="form1" target="apresenta" method="post" action="menu2.php" style="position:absolute; top:70;left:10
border:thin; border-style:none;">
<label> Atualizar dados </label><br>
Numero: <input type="text" name="num" value=""><br>
Texto: <input type="text" name="texto" value=""><br>
Imagem: <input type="file" name="imagem" value=""><br>
<input type="submit" name="submit" value="enviar">
<input type="reset" value="limpar">
</form>
</div>
</body>
</html>
为什么使用addslashes(file_get_contents(?请参见:https://www.w3schools.com/php/php_file_upload.asp –
)为什么要增加数据库大小?不好的做法是将文件存储在在数据库中,您应该借助文件系统将它们存储在服务器上,如果您仍然希望将这些文件保存在数据库中,您首先需要将它们转换为base64格式或以我们可以保存在数据库中的任何其他格式。 – itzmukeshy7
A处理这个问题的常用方法是将图像存储在文件系统中,然后在数据库中存储图像的路径 – fredrover