note 88038 modified in function.header by danbrown

From: Date: Thu, 08 Jan 2009 15:50:29 +0000
Subject: note 88038 modified in function.header by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148956@lists.php.net to get a copy of this message
When you are trying to download a file using PHP it´s important to take into acount the definition of de Header element. I have seen various examples where the people use a <?php header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$filename."\";"); ?> however in adition to this is important add the definition of the cache because if you dont do it you will have problems with some navigators for example IE 7.0 under https protocol will show you a message saying that the file is not available. here is a working example: <?php header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header ( "Content-Type: $filedatatype" ); header("Content-Disposition: attachment; filename=\"".$FileObj->name."\";"); header("Content-Transfer-Encoding:­ binary"); header("Content-Length: ".$filesize); readfile($file); exit; ?> where $filedatatype is the data type of the file for example: application/pdf --was-- When you are trying to download a file using PHP it´s important to take into acount the definition of de Header element. I have seen various examples where the people use a header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$filename."\";"); however in adition to this is important add the definition of the cache because if you dont do it you will have problems with some navigators for example IE 7.0 under https protocol will show you a message saying that the file is not available. here is a working example: header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header ( "Content-Type: $filedatatype" ); header("Content-Disposition: attachment; filename=\"".$FileObj->name."\";"); header("Content-Transfer-Encoding:­ binary"); header("Content-Length: ".$filesize); readfile($file); exit; where $filedatatype is the data type of the file for example: application/pdf http://php.net/manual/en/function.header.php

« previous php.notes (#148956) next »