I have a problem - as topic says, I need to insert images into database. Unfortunately, I don't know how.
What do I need: Browse button by which the user uploads some picture into database. If I have set my table setting correctly, data types in database should be "BLOB".
I did this and when I tried uploading in browser in my MySQL database, everything went great. Picture was uploaded and when I clicked on it, it displayed. But when I uploaded pictures by my PHP code, it's not saved in the format as it used to be, but in format ".bin".
There is my code:
this is from my class - "funkce"
mysql_query("INSERT INTO foto (id_pronajem_pokoj_nabizim, foto, foto2, foto3, foto4, foto5, foto6, foto7, foto8, foto9, foto10) VALUES ('$id_pronajem_pokoj_nabizim', '$foto', '$foto2', '$foto3', '$foto4', '$foto5', '$foto6', '$foto7', '$foto8', '$foto9', '$foto10')");
my form:
<form method="GET" action="index.php?vlozit">
<div>
<table>
<tr>
<td><h2><u>Foto:</u></h2></td>
</tr>
<tr>
<td><input type="file" name="foto"></td>
</tr>
<tr>
<td><input type="file" name="foto2"></td>
</tr>
<tr>
<td><input type="file" name="foto3"></td>
</tr>
<tr>
<td><input type="file" name="foto4"></td>
</tr>
<tr>
<td><input type="file" name="foto5"></td>
</tr>
</table>
</div>
<a href="index.php?vlozit"><input type="submit" value="Ulozit a pokracovat" name="prvni_stranka"></a>
</form>
sending values from form:
<?php
if (isset($_GET['prvni_stranka']))
{
$funkce->vloz_prvni($_GET['foto'], @$_GET['foto2'],
@$_GET['foto3'], @$_GET['foto4'], @$_GET['foto5'], @$_GET['foto6'], @$_GET['foto7'], @$_GET['foto8'], @$_GET['foto9'], @$_GET['foto10']);
}
?>
I didn't know how to do this thing. That's why I have 10 rows in my table "foto" and if there are for example just 4 pictures, others are null.
Any help will be highly appreciated.
mysql_*
functions are deprecated.$_GET
but$_FILES
. Don't use@
. You must haveenctype
in your form...