Laravel在使用HTTPS

时间:2018-03-23 13:05:38

标签: php laravel ssl https binary

我的laravel项目中有一些zip文件,它们是通过简单的方法下载的

return response()->download($path);

现在我添加了强制https到网站:

if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' ||
   $_SERVER['HTTPS'] == 1) ||
   isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
   $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
{
   $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header('HTTP/1.1 301 Moved Permanently');
   header('Location: ' . $redirect);
   exit();
}

现在我无法读取zip文件,它们似乎已损坏。

我在十六进制编辑器中打开了其中一个,我发现在开头有一个额外的0a0a字符。

我不知道为什么会这样,这意味着什么。尤其是如何修复它,而无需编辑下载的文件。

1 个答案:

答案 0 :(得分:0)

可能是您的标题尝试查看此博文,看看这是否是您问题的解决方法。

https://perishablepress.com/http-headers-file-downloads/

<?php // HTTP Headers for ZIP File Downloads
// https://perishablepress.com/press/2010/11/17/http-headers-file-downloads/

// set example variables
$filename = "Inferno.zip";
$filepath = "/var/www/domain/httpdocs/download/path/";

// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
ob_end_flush();
@readfile($filepath.$filename);
?>