A simple solution is to create a file .php
to manipulate the display of your images. You can create the following url to access your images: obterImagens.php?nome=nome_da_imagem
Html code for image requests
<img src="obterImagens.php?nome=imagem1" class="img-responsive"
width="300px" height="300px" align="#">
<img src="obterImagens.php?nome=imagem2" class="img-responsive"
width="300px" height="300px" align="#">
PHP code to return an image
Before the php code, I assume you have a table in the database similar to this:
|nome_imagem|local_imagem|
Assuming the images are saved in a directory in your file system we can return them using the function file_get_contents()
.
So, going back to php we can do this:
$nome_imagem = $_GET['nome'];
$conexao = mysqli_connect($conexao,'host', 'usuario', 'senha', 'nome_banco');
$consulta = mysqli_query('select * from imagens where nome_imagem = '
. "'" . $nome_imagem . "'");
//como o nome da imagem deve ser unico, apenas um registro deveria ser
//retornado
$resultado = mysqli_fetch_assoc($consulta);
//como o campo local_imagem é o caminho absoluto ou relativo para
//a imagem fica facil acessa-la agora.
$caminho_imagem = $resultado['local_imagem'];
//suponto que você salva todas as imagens no mesmo diretorio do script
//A varaivel $resultado['local_imagem'] poderia representar
//apenas o nome da imagem, e você poderia concatenar os dois
$mime = mime_content_type(__DIR__ . '/' . $caminho_imagem);
$tamanho = filesize(__DIR__ . '/' . $caminho_imagem);
header("Content-Type: ". $mime);
header("Content-Length: " . $tamanho);
//e por fim você manda para o navegador
echo file_get_contents(__DIR__ . '/' . $caminho_imagem);
This answer was adapted from a question available in the Sopt. IN THE Soen has a question (with answer) much closer than you want.
Ué, you will need php to get the database data.
– Francisco
yes I need php, what I do not know is how to make this code which command lines and where to save
– Mariano Ribeiro
visit this link to see an example https://imasters.com.br/artigo/3831/mysql/cadastrando-e-exibindo-imagens-diretamente-do-mysql-5/? trace=1519021197&source=single
– Maciel Sousa
I am saving in BD only the image paths, in a field VARCHAR and not BLOB, already visited this link and did all this and even though it did not work, I’m still new in this part of php and database, I know almost nothing
– Mariano Ribeiro
For you to get it you need to use a server-side programming language.. example of a php.. you already do this ? show your code so you can help more...
– Maciel Sousa
my code is all html with JS like this... <img src="img/pat.png" class="img-Responsive" width="300px" height="300px" align="#"></a> <div class="caption"> <p> <H4><b> Do Cardoso Restaurant</b> </b> <p align="Justify"> /> the connection part with the database I already did, what I don’t know how to do is the display part of the image in html via a php
– Mariano Ribeiro
I have already developed everything, but I saw that if you start saving the images inside the folder of the app, it will be very heavy, then I wanted to send to the bank and the bank display in the code, the part of sending to the database the images I have already made, through the path of them, now I just want to pull her from the bank and display on the screen, kind have the name of the restaurant and below the image I want this image coming directly from the database
– Mariano Ribeiro
this is the app, https://play.google.com/store/apps/details?id=br.com.mariano.jabukatur all his images are inside a folder in the same file and that weighs I wanted those images coming from the bank
– Mariano Ribeiro