-4
I want to display a photo registered in the database that was registered in a type blob attribute. However I do not want to display the photo through a link where you click and open the photo, on the page is forwarded the id where calls the function to select and show the data and the photo. The function at the bottom:
public function selecionarPetFoto($id,$pdo){
$sql = $pdo->prepare("SELECT Foto_pet FROM pet WHERE Cod_pet=:cdp LIMIT 1");
$sql->BindValue(':cdp',$id,PDO::PARAM_INT);
$sql->execute();
$sql->fetch(PDO::FETCH_OBJ);
}
NOTE: Everything is already registered and the data is already displayed correctly, only the photo that I can not display. Remembering is not wrong, it depends on the characteristics of your application and your operational needs.
The best efficient way to store and recover photos is in the file system leaving only the path recorded in the database. This is because blob and fields of variable size inflate and misalign the storage structure of lines, compromising the performance of queries.
– Augusto Vasques
Use 'base64_encode()' in the
blob
. If the photo is ajpeg
and$row
is a line returned by the query:echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['Foto_pet'] ).'"/>';
– Augusto Vasques
@Augustovasques And if I want to delete the photo with id selection and using delete, delete only the image path or delete the image in the server folder where it was stored?
– Robert Sousa
Only the way. Delete the image with
unlink()
.– Augusto Vasques
worked well using base64_encode(), I will study law to know which is more feasible
– Robert Sousa
Since no one has been able to give an answer, I am presenting.
– Augusto Vasques