【发布时间】:2018-05-23 11:47:45
【问题描述】:
我开发了一个通过安全 URL 传递文件的脚本,目的是模仿 Amazon S3 的私有文件托管。用户将向服务器发送请求,该服务器生成可用于访问文件的 URL。生成的 URL 在生成后 2 小时后过期。
这是脚本的解密部分:
$data = decrypt($_GET['data']);
$data_json = json_decode($data,true);
// print_r($data_json); die;
$elapsed = strtotime('now') - $data_json['expire'];
if ($elapsed > URLEXPIRE) {
echo json_encode(array(
'status'=>false,
'error'=>'URL expired.',
'debug'=>$data,
'debug2'=>$_GET['data']
));
die;
}
$object = OBJECTSTORE . $data_json['path'];
header('X-Elapsed: ' . $elapsed);
// header('Content-Type: '.get_mime_type($object));
header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename=' . basename($object));
if (strpos($data_json['path'],'?download'))
header('Content-Disposition: attachment;');
// echo file_get_contents($object);
readfile($object);
die;
在我的登台服务器上进行测试期间,脚本运行良好。但是,在交付大型视频文件时在生产中发布时,它似乎很慢。将 URL 作为 HTML 视频标签的源加载需要一段时间。我不知道这是否有帮助,但 decrypt 函数使用 openssl_decrypt 使用 AES-256-CBC 密码。
有什么更有效的方法吗?
【问题讨论】:
-
您可以将 apache 与 mod_auth_basic 和 https 一起使用。或您喜欢的其他网络服务器。
标签: php openssl php-openssl