嗨,我让用户购买贝宝隐藏的虚拟mov.zip文件。我得到了交易部分,并将细节存储在数据库中等。但是,在用户返回到事务页面后,我想将它们链接到一个受限制文件夹中的压缩文件(.htaccess,全部拒绝)。我如何授予他们访问此目录的权限,以便在几天内下载该文件。我暂时不能将文件移出目录,因为它太大了(它是一个高清动作特效包)。
谢谢。
发布于 2012-08-03 02:26:30
如果您的主机允许您更改脚本超时的PHP设置,您只需通过检查用户访问的PHP脚本来流式传输文件即可。
例如,请求:
>http://domain.com/download.php?file=be6bc64c94bbc062bcebfb40b4f93304
<?php
session_start();
if (!isset($_GET['file']) header('Location: index.php'); // invalid request
// 1. check user session
...
// 2. get file from hash (use a Db like MySQL
$file = ...;
// 3. check user privilege for the given file
...
// 4. proceed to download
if (file_exists($file)) {
set_time_limit(0);
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;
} else {
// error 404
}https://stackoverflow.com/questions/11783481
复制相似问题