msolutions / file-access-encryptor
使用过期时间加密真实文件路径
v1.0.1
2022-05-22 05:25 UTC
Requires
- php: ^7.4|^8.0|^8.1
- illuminate/filesystem: ^8.0|^9.0
This package is not auto-updated.
Last update: 2024-09-22 16:30:55 UTC
README
版本 1.0
这个库将支持您隐藏/防止通过真实位置访问文件
特性
- 隐藏文件真实位置
- URL 过期
- 重新生成安全的唯一 URL
安装
composer require msolutions/file-access-encryptor
实现
use MSL\FileAccessEncryptor;
/*initialize the class inside your
*constructor or any other function before using
**/
public function __constructor()
{
new FileAccessEncryptor();
}
//Generate encrypted token for your files
$realFilePath = '/path/pdf/mypdf.pdf';
$urlExpirationTime = 60; //60 seconds (apply the time in seconds)
$encryptedToken = FileAccessEncryptor::encryptRealPath($realFilePath, $urlExpirationTime);
解密令牌
use MSL\FileAccessEncryptor;
/*initialize the class inside your
*constructor or any other function before using
**/
public function __constructor()
{
new FileAccessEncryptor();
}
//decrypt the token and get the real file path
FileAccessEncryptor::name("Give-Some-File-Name"); //optional
//encryption value mutation to get the real url (optional)
FileUrlEncryptor::mutateRealPath(function($value){
return $value+1;
});
//Preview the file (if need to preview the secure object)
$encryptedToken = 'ENC-TOKEN';
FileAccessEncryptor::type("pdf"); //[pdf, jpg, jpeg] parse here your file type for preview purpose
FileUrlEncryptor::preview($encryptedToken);
//decrypt and get the real file path and expiry status
$encryptedToken = 'ENC-TOKEN';
$result = FileAccessEncryptor::decryptRealPath($encryptedToken);
/*
return ["status" => "valid", "path" => "/path/for-real-file.pdf"];
OR
return ["status" => "expired", "path" => null];
*/
这个开源包是为通用目的开发的,任何开发者都可以免费使用。
- 请分享您的评论和想法以改进此包。