gpt4 book ai didi

php - 如何密码保护二进制文件下载?

转载 作者:行者123 更新时间:2023-12-04 05:01:04 24 4
gpt4 key购买 nike

我想在任意二进制文件上创建一个非常简单的 php 保护程序,用户输入密码并将文件下载到他们的计算机,但他们每次要下载时都必须输入密码。

first answer问题 Easy way to password-protect php page ,线路include("secure.html");似乎要求文件必须是可显示的 ascii,可由浏览器呈现。

有没有办法保护二进制文件,比如 foo.bin具有相同级别的简单性(以及类似的有限安全性)?

最佳答案

将文件夹设置为存储文件的位置以拒绝所有,然后使用 readfile 您应该能够访问它。

<?php
if (!empty($_POST)) {
$user = $_POST['user'];
$pass = $_POST['pass'];

if($user == "admin"
&& $pass == "admin")
{
$file = 'path/to/file';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
}
?>

<form method="POST" action="">
User <input type="TEXT" name="user"></input>
Pass <input type="TEXT" name="pass"></input>
<input type="submit" name="submit"></input>
</form>

关于php - 如何密码保护二进制文件下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16137408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com