3
Good morning!
I intend to insert an image into the database in the format . jpg, but when it is inserted it appears like this in the database: ???? JFIF
Here is my code for the image:
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="imagem" placeholder="Insira a imagem do produto" required/>
</form>
<?php
$imagem_produto=addslashes(file_get_contents($_FILES['imagem']['tmp_name']));
$inserir_produto=mysqli_query($link,"INSERT INTO produtos (imagem) VALUES('{$imagem_produto}')");
?>
What he wanted was for the name and extension of the image to appear in the database, for example "image.jpg" only this!
The name and the extension! because without the extension will not be worth anything :/
– Ana
With that he’ll get both
– I_like_trains
Yes I am also using varchar. I tried to implement your code, but it is a mistake , it does not say which... And by the way in your
if
"images/ would be the right folder name?– Ana
@Ana Yes but gives error in which line? You do the
submit
form?– I_like_trains
It does not say which line is wrong, it appears the error that comes from
echo "erro";
And yes I do form Ubmit– Ana
The path of that briefcase is right?
– I_like_trains
@Ana this means that she could not move the image that was loaded to the final folder, in this case
images
. Probably the path to the folderimages
is different.– Leite
The way to the briefcase in my case would be
../images/
and yes he is correct :/ I apologize for the inconvenience by the way...– Ana
But it’s working right?
– I_like_trains
Well, I appreciate all your help, it’s working at last!!
– Ana
this code gives me error with ";" in query
– José Gomes
@Joségomes as well as so?
– Ana
when putting this code in my project it gives error in the query ;
– José Gomes
was missing a ")" here -- if(move_uploaded_file($_FILES['image']['tmp_name'], "images/". $im_name){
– José Gomes
@Thank you Joségomes! I will correct immediately
– I_like_trains