Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/07/2010, 18:20
Avatar de maycolalvarez
maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Botón Descarga

a eso le llamamos force download, y consiste en enviar las cabeceras HTTP adecuadas para obligar al navegador a mostrar el cuadrito, para ello se usa comúnmente un script de lado del servidor, como pho, asp o jsp.

ejemplo php force download:

Código PHP:
Ver original
  1. <?php
  2. $file = 'monkey.gif';
  3.  
  4. if (file_exists($file)) {
  5.     header('Content-Description: File Transfer');
  6.     header('Content-Type: application/octet-stream');
  7.     header('Content-Disposition: attachment; filename='.basename($file));
  8.     header('Content-Transfer-Encoding: binary');
  9.     header('Expires: 0');
  10.     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  11.     header('Pragma: public');
  12.     header('Content-Length: ' . filesize($file));
  13.     ob_clean();
  14.     flush();
  15.     readfile($file);
  16.     exit;
  17. }
  18. ?>
fuente