christiansalazarh

Entregar archivo al browser

Jan 19th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. // FORMA 1 (mas segura y con un objeto de clase Attachment que mediante un ID representa un documento previamente creado, cuyo contenido se alojo en un campo LONGBLOB llamado filecontent)
  2. public function actionViewPdf($id) {
  3.         $model = Attachment::model()->findByPk($id);
  4.     header("Cache-Control: public");
  5.     header("Content-Type: application/pdf");
  6.     echo $model->filecontent;
  7. }
  8.  
  9. // FORMA 2 (solo para aclarar el ejemplo, no es seguro usar esto asi, solo es para mostrar que se debe leer un nombre de archivo leerlo y entregarselo al browser)
  10. public function actionViewPdf($filename) {
  11.     header("Cache-Control: public");
  12.     header("Content-Type: application/pdf");
  13.     readfile($filename);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment