I never moved with uploading files and today I really need to do so. I have a code to test, and then use it on the site.
Here I have HTML :
<html>
<body>
<form action="inserir.php" method="POST" enctype="multipart/form-data">
<label>File: </label><input type="file" name="imagem" />
<input type="submit" />
</form>
</body>
</html>
And here's PHP :
<?php
$con = mysqli_connect("localhost","root","", "teste3");
$image = addslashes(file_get_contents($_FILES['imagem'])); //SQL Injection defence!
$image_name = addslashes($_FILES['imagem']);
$sql = "INSERT INTO testeimg (imagem) VALUES ({$imagem})";
if(mysqli_query($con, $sql)){
echo "<script>alert('Sucesso');</script>";
}
else{
echo mysqli_connect_error();
}
?>
I've been searching a bit and this is what gave me, but it gives me error inserting into the BD .
Can anyone help me with this?
I have a database:teste3
, table: testeimg
with id
auto_increment PK
and imagem
with LONGBLOB
.