download of imagenen that is in the DB

0

as I do to download and to show on screen a previously loaded image to the database

This is the php that seeks to load the image I do with the variable but the only thing that loads is the name of the image

                        <?php
                             include('is_logged.php');//Archivo verifica que 
                    el usario que intenta acceder a la URL esta logueado
                  /* Connect To Database*/
           require_once ("../config/db.php");//Contiene las variables de 
           configuracion para conectar a la base de datos
            require_once ("../config/conexion.php");//Contiene funcion que 
              conecta a la base de datos
         $action = (isset($_REQUEST['action'])&& $_REQUEST['action'] 
        !=NULL)?$_REQUEST['action']:'';
          if (isset($_GET['Nticket'])){
        $incidencia=intval($_GET['Nticket']);
          $query=mysqli_query($con, "select * from ticket where 
         Nticket='".$Nticket."'");
             $rw_user=mysqli_fetch_array($query);
             $count=$rw_ticket['Nticket'];
          if ($Nticket!=1){
    if ($delete1=mysqli_query($con,"DELETE FROM ticket WHERE Nticket='".$Nticket."'")){
    ?>
    <div class="alert alert-success alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <strong>Aviso!</strong> Datos eliminados exitosamente.
    </div>
    <?php 
}else {
    ?>
    <div class="alert alert-danger alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <strong>Error!</strong> Lo siento algo ha salido mal intenta nuevamente.
    </div>
    <?php

}

} else {
    ?>
    <div class="alert alert-danger alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <strong>Error!</strong> No se pudo eliminar ésta  categoría. Existen productos vinculados a ésta categoría. 
    </div>
    <?php
}



           }
            if($action == 'ajax'){
            // escaping, additionally removing everything that could be 
       (html/javascript-) code
  $q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], 
        ENT_QUOTES)));
 $aColumns = array('Nticket');//Columnas de busqueda
 $sTable = "ticket";
 $sWhere = "";
if ( $_GET['q'] != "" )
{
    $sWhere = "WHERE (";
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        $sWhere .= $aColumns[$i]." LIKE '%".$q."%' OR ";
    }
    $sWhere = substr_replace( $sWhere, "", -3 );
    $sWhere .= ')';
}
$sWhere.=" order by Nticket";
include 'pagination.php'; //include pagination file
//pagination variables
$page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
$per_page = 10; //how much records you want to show
$adjacents  = 4; //gap between pages after number of adjacents
$offset = ($page - 1) * $per_page;
//Count the total number of row in your table*/
$count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM $sTable  $sWhere");
$row= mysqli_fetch_array($count_query);
$numrows = $row['numrows'];
$total_pages = ceil($numrows/$per_page);
$reload = './clientes.php';
//main query to fetch the data
$sql="SELECT * FROM  $sTable $sWhere LIMIT $offset,$per_page";
$query = mysqli_query($con, $sql);
//loop through fetched data
if ($numrows>0){
    ?>
<div class="table-responsive">
      <table class="table">
        <tr  class="danger">
            <th>ticket</th>
            <th>Incidencia</th>
            <th>Tema</th>
            <th>Detalle</th>
        </tr>
            <?php
    $nums=0;
        while ($row=mysqli_fetch_array($query)){
                $Nticket=$row['Nticket'];
                $incidencia=$row['incidencia'];
                $tema=$row['tema'];
                $detalle=$row['detalle'];
                 $_FILES['imagen']['name']=$row['imagen'];

                $nums++;



                ?>


            <input type="hidden" value="<?php echo $row['Nticket'];?>" id="Nticket<?php echo $Nticket;?>">
            <input type="hidden" value="<?php echo $row['incidencia'];?>" id="incidencia<?php echo $incidencia;?>">
            <input type="hidden" value="<?php echo $row['tema'];?>" id="tema<?php echo $tema;?>">
            <input type="hidden" value="<?php echo $row['detalle'];?>" id="detalle<?php echo $detalle;?>">
            <input type="hidden" value="<?php echo $row['imagen'];?>" id="imagen<?php echo $_FILES['imagen']['name'];?>">
            <tr>
                <td><?php echo $Nticket; ?></td>
                <td><?php echo $incidencia; ?></td>
                <td><?php echo $tema; ?></td>
                <td><a data-toggle="modal" href="#myModal_<?php echo $nums; ?>"><li 
               class='glyphicon glyphicon-info-sign'></li></a>
            <div class="modal fade" id="myModal_<?php echo $nums; ?>" role="dialog">
       <div class="modal-dialog">
       <div class="modal-content">
      <div class="modal-header">
   <button type="button" class="close" data-dismiss="modal">&times;
          </button>
       <h4 class="modal-title">Detalle de la incidencia</h4>
   </div>
    <div class="modal-body">
    <p><?php echo $detalle;?></p>
    <p><?php echo $_FILES['imagen']['name'];?></p>
 </div>
  <div class="modal-footer">
   <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
  </div>
  </div>

      </div>
 </div>

                                                                                                                                                              

test

    
asked by Kevin Salazar 29.09.2017 в 00:39
source

1 answer

1

Hello again hehehe this happens because in no time you are "copying" the image to a directory of your site, you are only saving the name in the database.

To copy the image you must do the following in the php in which you insert the data to the table:

$imagen = $_FILES['imagen']['name']; //Esta variable ya la estás capturando
$ruta_tmp = $_FILES['imagen']['tmp_name'];

$ruta_final = '../img/' . $imagen; //Debes tener mucho cuidado con la forma en que haces la ruta del directorio, si la copias mal no se moverá correctamente la imagen

if (!file_exists($ruta_final)) {
    move_uploaded_file($ruta_tmp, $ruta_final);
}

After this you can verify that the image has been copied to the directory you placed in the variable $ruta_final and you call it from html with a label img like this:

<img src="img/<?php echo $_FILES['imagen']['name']; ?>">

I hope you serve, greetings!

    
answered by 29.09.2017 / 00:51
source