How to show an image whose path is in the database?

0

I'm using ExtJS 4 and PHP.

I have a saved image in a folder on the server and its path is saved to my database. I tried to do something like this:

No controller code:

onVerImgClick: function(btn, o, e0pts){
    var grid = btn.up('grid');
    var records = grid.getSelectionModel().getSelection();
    var produtoId = records[0].data.id;
    //var image = Ext.create('ExtMVC.view.verImagem');
    Ext.Ajax.request({
        method: 'POST',
        url: 'php/importadorDadosImagem.php',
        success: function(response){
            var array = Ext.decode(response.responseText);
            var cont = 0;
            var caminho;
            while(cont < array.data.length){
                if(produtoId == array.data[cont].idProduto){
                    caminho = array.data[cont].imagem;
                }
                cont++;
            }
            cont = 0;
            if(caminho != null){
                var image = Ext.create('ExtMVC.view.verImagem');
                image.getEl().set({
                    src: caminho
                });
            }
        }
    });
}

verImagem.js

Ext.define('ExtMVC.view.verImagem', {
   extend: 'Ext.window.Window',
   alias: 'widget.verimagem',
   autoShow: true,
   modal: true,
   width: 400,
   height: 400,
   items: [
       {
           xtype: 'component',
           autoEl: {
               tag: 'img',
               src: ' '
           }
       }
   ]
});

importerDataImage.php

<?php
include("connect.php");

$queryString = "SELECT idProduto, imagem FROM imagens";

//consulta sql
$query = mysql_query($queryString) or die(mysql_error());

//faz um looping e cria um array com os campos da consulta
$dados = array();
while($dado = mysql_fetch_assoc($query)) {
    $dados[] = $dado;
}

$total = count($queryString);

echo json_encode(array(
    "success" => mysql_errno() == 0,
    "total" => $total,
    "data" => $dados
));

In this way, no error is shown. However, the image does not appear.

    
asked by anonymous 04.02.2015 / 11:41

1 answer

1

Good morning, have you tried to connect to the database first by PHP? you have to have in the database the following information, name and extension of the image, then in php you poe in a variable, the full address of the root folder up to the folder where the image is, then concatenate with the name and extension of the image , ai just insert in a javascript variable and assign in your code to display the image.

example

SQL = name | ext = image.ext

PHP = server / folder / subfolder / image.ext

EJS = link

    
04.02.2015 / 12:53