0
I am trying to put a php script to resize images dynamically, until then I had no problem. I have a folder that is saved the images that were edited by the script and the images arrive right, only I wanted the name of the image was also saved in the database.
$sql = "SELECT * FROM foto WHERE foto = '6671.jpg' OR foto = '6672.jpg'";
$query = mysqli_query($conecta, $sql);
while ($linha = mysqli_fetch_array($query)) {
$img_origem = ImageCreateFromJpeg($linha['foto']);
$largura = imagesx($img_origem);
$altura = imagesy($img_origem);
$nova_largura = 200;
$nova_altura = $altura * $nova_largura / $largura;
$img_destino = imagecreatetruecolor($nova_largura, $nova_altura);
imagecopyresampled($img_destino, $img_origem, 0, 0, 0, 0, $nova_largura, $nova_altura, $largura, $altura);
$up = imageJPEG($img_destino,'teste/'. rand() . '.jpg', 85);
$sql = "INSERT INTO foto (foto) VALUES ('" . $up . "')";
$query = mysqli_query($conecta, $sql);
}
I don’t understand what’s wrong with your script.
– mau humor
my problem is when inserting this resized image in the bank, that variable $up does not take the name of the image. the value assigned to it is always 1. but in my test folder the image is stored normally.
– fabricio
But the Imagejpeg function does not return the file name according to the documentation: http://php.net/manual/en/function.imagejpeg.php
– mau humor
in fact the Imagejpeg function returns the correct name, at least in the test folder it is saved correctly. but if I give an echo in the variable $up it has the value of 1
– fabricio
Bianca, vc is saving with name Rand(), but is inserting a Boolean in the bank of value 1. What the bad mood said is q in the documentation the return of the function is boolean.
– Antonio Alexandre