regdude Posted March 16, 2009 Share Posted March 16, 2009 Hi! header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public", false); header("Content-Description: File Transfer"); header("Content-Type: application/zip"); header("Accept-Ranges: bytes"); header("Content-Disposition: attachment; filename=$zipfilepath"); header("Content-Transfer-Encoding: binary"); $zipfilepath is something like /var/www/site/htdocs/folder/something-001.zip When I open the page it starts downloading a file, that size is 1 kb and when I open it is damaged, because the file wasn't downloaded right. The path is right in $zipfilepath! Link to comment https://forums.phpfreaks.com/topic/149727-header-hiding-url/ Share on other sites More sharing options...
thebadbad Posted March 16, 2009 Share Posted March 16, 2009 Well, $zipfilepath is only defined as the filename here. You have to read in the actual file after the headers: <?php header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public", false); header("Content-Description: File Transfer"); header("Content-Type: application/zip"); header("Accept-Ranges: bytes"); header("Content-Disposition: attachment; filename=" . basename($zipfilepath)); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($zipfilepath)); //output file to script readfile($zipfilepath); ?> And I ran the filename through basename() to name it something-001.zip and not the whole path. I also added the content-length header. Link to comment https://forums.phpfreaks.com/topic/149727-header-hiding-url/#findComment-786262 Share on other sites More sharing options...
regdude Posted March 16, 2009 Author Share Posted March 16, 2009 It works, thanks! Link to comment https://forums.phpfreaks.com/topic/149727-header-hiding-url/#findComment-786267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.