Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/10/2015, 18:50
Avatar de xfxstudios
xfxstudios
 
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: Forzar descarga de Imagen

No te queda de otra:

Los enlaces
Código HTML:
Ver original
  1. <a href="testb.php?file=1.jpg">Descargar</a>

El archivo unico php que va a procesar y a forzar la descarga:

Código PHP:
Ver original
  1. <?php
  2.  
  3. if (!isset($_GET['file']) || empty($_GET['file'])) {
  4.  exit();
  5. }
  6. $root = $_SERVER['DOCUMENT_ROOT']."/imagenes/slider/";
  7. $file = basename($_GET['file']);
  8. $path = $root.$file;
  9. $type = '';
  10.  
  11. if (is_file($path)) {
  12.  $size = filesize($path);
  13.  if (function_exists('mime_content_type')) {
  14.  $type = mime_content_type($path);
  15.  } else if (function_exists('finfo_file')) {
  16.  $info = finfo_open(FILEINFO_MIME);
  17.  $type = finfo_file($info, $path);
  18.  finfo_close($info);
  19.  }
  20.  if ($type == '') {
  21.  $type = "application/force-download";
  22.  }
  23.  // Definir headers
  24.  header("Content-Type: $type");
  25.  header("Content-Disposition: attachment; filename=$file");
  26.  header("Content-Transfer-Encoding: binary");
  27.  header("Content-Length: " . $size);
  28.  // Descargar archivo
  29.  readfile($path);
  30. } else {
  31.  die("El archivo no existe.");
  32. }
  33.  
  34. ?>

si almacenas las imagenes en un solo directorio no tendras mucho rollo con la configuracion
__________________
[email protected]
HITCEL