【发布时间】:2018-06-18 14:29:28
【问题描述】:
我有压缩、加密的文件。 压缩文件虽然有其原始扩展名。他们没有 .zip 或任何其他压缩扩展名。
我具有以下功能,可以解密文件然后将其提供给下载。 所以当我现在下载文件时,我得到的是解密的文件,但仍然是压缩的。
下载前我需要帮助来实现解压。
function Download($path,$type,$key,$iv){
if($type=="File"){
if (file_exists($path)) {
$fileBuffer = file_get_contents($path);
$iv = str_pad($iv, 16, "\0");
$cipher = base64_decode($fileBuffer);
$plain = openssl_decrypt($cipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
file_put_contents($path, $plain);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
readfile($path);
$fileBuffer = file_get_contents($path);
$iv = str_pad($iv, 16, "\0");
$cipher = openssl_encrypt($fileBuffer, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
$cipher64 = base64_encode($cipher);
file_put_contents($path, $cipher64);
exit;
}
【问题讨论】:
-
有多种压缩算法和格式。您需要准确指定用于压缩的算法和格式。
-
它是一个简单的 .zip,但 .zip ext 已从文件名中删除,因此文件类似于 example.jpg
标签: php file encryption download unzip