insert a picture in BLOB

A

Anonymous

Guest
i need to insert a tumb in a BLOB, this is my code
Code:
<?
include("conect.php");  
$hoy = date("d")." de ".date("M")." del ".date("Y");

// here is created the tumb

$imagen_origen=ImageCreateFromJPEG($nombre);
$ancho=imagesx($imagen_origen);
$alto=imagesy($imagen_origen);
$tancho=$ancho;
$talto=$alto;
if ($alto == $ancho) {
$alto=100;
$ancho=100;
} else {
if ($alto > $ancho) {
$ancho = ($ancho * 100 / $alto);
$alto=100;
} else {
$alto = ($alto * 100 / $ancho);
$ancho=100;
}}
$imagen_destino=ImageCreateTrueColor($ancho, $alto);
imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tancho, $talto);

// here i must do something to $imagen_destino i guess

mysql_query("insert into perras (fecha, tumb) values ('$hoy', '$imagen_destino')",$link);

$result = mysql_query("SELECT id FROM perras ORDER BY id DESC LIMIT 1", $link);
while ($myrow=mysql_fetch_array($result))
{
$ultimoid=$myrow["id"];
}

//ImageJPEG($imagen_destino,'',75);
// last tumb

$result = mysql_query("SELECT tumb FROM perras where id = $ultimoid", $link);
while ($myrow=mysql_fetch_array($result))
{ 
echo $myrow['tumb']; 
}
echo "<br>";
echo $alto;
echo "<br>";
echo $ancho;

?>
 
Code:
mysql_query("insert into perras (fecha, tumb) values ('$hoy', '$imagen_destino')",$link);

you are telling mysql you are going to insert into 2 fields put you specify 3. This will not work. you need to have (fecha, tumb, link)
 
Redcircle said:
Code:
mysql_query("insert into perras (fecha, tumb) values ('$hoy', '$imagen_destino')",$link);

you are telling mysql you are going to insert into 2 fields put you specify 3. This will not work. you need to have (fecha, tumb, link)

I only see two fields and two values there - (fetcha, tumb), ('$hoy', '$imagen_destino'). Two and two.
 
ahh.. your are correct.. my eyes are not used to seeing the connection in the query.
 
tumb is a BLOB, i try to insert $imagen_destino, but i need to do something, i don´t know what...
 
$imagen_destino is just an image identifier you need to create the image using imagejpeg (
 
Here is the code

<?
include("conect.php");
$hoy = date("d")." de ".date("M")." del ".date("Y");

// here is created the tumb

$imagen_origen=ImageCreateFromJPEG($nombre);
$ancho=imagesx($imagen_origen);
$alto=imagesy($imagen_origen);
$tancho=$ancho;
$talto=$alto;
if ($alto == $ancho) {
$alto=100;
$ancho=100;
} else {
if ($alto > $ancho) {
$ancho = ($ancho * 100 / $alto);
$alto=100;
} else {
$alto = ($alto * 100 / $ancho);
$ancho=100;
}}
$imagen_destino=ImageCreateTrueColor($ancho, $alto);
imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tancho, $talto);

// here i must do something to $imagen_destino i guess
ImageJPEG($imagen_destino,'',75);

mysql_query("insert into perras (fecha, tumb) values ('$hoy', '$imagen_destino')",$link);

$result = mysql_query("SELECT id FROM perras ORDER BY id DESC LIMIT 1", $link);
while ($myrow=mysql_fetch_array($result))
{
$ultimoid=$myrow["id"];
}

// last tumb

$result = mysql_query("SELECT tumb FROM perras where id = $ultimoid", $link);
while ($myrow=mysql_fetch_array($result))
{
echo $myrow['tumb'];
}
echo "<br>";
echo $alto;
echo "<br>";
echo $ancho;

?>

i made this change
ImageJPEG($imagen_destino,'',75);
but i only get :

Resource id #6

but not the picture
 
http://www.phpbuilder.com/columns/florian19991014.php3?aid=38
 
Code:
ImageJPEG($imagen_destino,'/path/to/file',75);
$binarydata = file_get_contents(/path/to/file);
unlink (/path/to/file);
mysql_query('insert into table.. .values .. (.., $binarydata, ..)')
 
Back
Top