1
I never touched uploading files and today I really need to do it. I have a code to test, to then use it on the site.
Here’s the 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 the 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 doing some research and this is what I did, but it makes me feel wrong to insert BD.
Can someone help me with this?
PS: I have a database: teste3
, table: testeimg
with id
auto_increment PK
and imagem
with LONGBLOB
.
I don’t advise you to save images directly in the comic book. You should have the images somewhere and in the comic book only the path for the image.
– Jorge B.
But if you want to keep it, you must use it
$_FILES['imagem']['tmp_name']
to save the image to the BD.– Jorge B.
@Jorgeb. Thank you for the suggestion! Can you show me a place to learn how to do that? I just don’t know (now I know a little but I’m still a turnip)
– Bruno Gibellino
@Jorgeb. As I point out to the image go to an Upload folder
– Bruno Gibellino
You can see the example in my reply.
– Jorge B.