Jump to content

Header - hiding url


regdude

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.